You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can examples of composition and inheritance of wrapped objects be added? I think one could potentially figure it out with the current examples, but I'm not able to figure it out.
classBasicClass { int IntValue; };
classBasicComposition
{
int foo;
BasicClass bc;
};
classBasicInheritance : BasicClass
{
double yValue;
};
classInheritanceAndComposition : BasicInheritance
{
std::string strValue;
BasicComposition bcValue;
};
// Export all classes to JS
One should be able to instantiate and use each C++ class in JavaScript (e.g. create an instance of BasicClass independent of instances of BasicComposition).
It seems to me that only the case of BasicClass has an example in 6_object_wrap. The other cases with inheritance and composition of classes extending ObjectWrap<T> do not appear to exist. Inheritance might be covered in inherits_from_event_emitter, but it is not clear to me what is going on in that example.
I'm hoping someone with more experience with node-addon-api can provide these types of examples. It would greatly assist me in defining more complex relationships in Napi.
The text was updated successfully, but these errors were encountered:
@AeromXundes inheritance is an unaddressed problem in the V8 implementation of N-API. That is, V8 exposes the ability to properly inherit from a JavaScript class only in a V8-specific fashion (by maintaining access to the v8::FunctionTemplate), which is something we cannot use in N-API. Thus, we cannot easily provide an API for creating JavaScript class hierarchies which correspond to C++ class hierarchies.
The only workaround is to structure the C++ portion of the code as a flat list of functions or as distinct classes by deriving from Napi::ObjectWrap, and to establish the JavaScript class hierarchy in pure JavaScript (nodejs/node-addon-api#229 (comment)).
Can examples of composition and inheritance of wrapped objects be added? I think one could potentially figure it out with the current examples, but I'm not able to figure it out.
One should be able to instantiate and use each C++ class in JavaScript (e.g. create an instance of
BasicClass
independent of instances ofBasicComposition
).It seems to me that only the case of
BasicClass
has an example in 6_object_wrap. The other cases with inheritance and composition of classes extendingObjectWrap<T>
do not appear to exist. Inheritance might be covered in inherits_from_event_emitter, but it is not clear to me what is going on in that example.I'm hoping someone with more experience with node-addon-api can provide these types of examples. It would greatly assist me in defining more complex relationships in Napi.
The text was updated successfully, but these errors were encountered: