@kaysonwu I think the problem is this line Pet(Pet::New(info.Env(), info[1].As<Napi::String>()))
This results in a a Pet JavaScript object that will only live as long as the method Hero::Hero is running since the object is not returned by the method and no JavaScript object references the object in the JavaScript heap. You do have a reference at the C++ level but that will not keep the object alive.
@kaysonwu hopefully @mhdawson's suggestion solved the problem you were experiencing. Please re-open the issue if you believe there is any functionality in node-addon-api that needs to change to better support your use case!
I have the following 2 classes, now I need to encapsulate Hero into a node module
I refer to the Wrapping C++ Object example, but I cannot complete the encapsulation of the
GetPetmethod in theHeroclass.How can I implement
GetPetto return thePetobject and customize its public methods?The text was updated successfully, but these errors were encountered: