-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get the Napi::Function constructor of an object? #897
Comments
There is no way to retrieve an object's constructor within Node API. You might be able to call auto objGlobal = env.Global().Get("Object");
auto getPrototypeOf = objGlobal.As<Object>().Get("getPrototypeOf").As<Function>();
auto prototype = getPrototypeOf.Call(objGlobal, { value }); // where `value` is the object whose prototype you want to receive |
thanks, but I think I'm not trying to get an objects constructor, but rather the constructor for a given type. How would you recommend to check if an object is of type Date? I'll try |
Hi @sezanzeb, Napi::Value Method(const Napi::CallbackInfo& info) {
bool isDate = info[0].IsDate();
return Napi::Boolean::New(env, isDate);
} I hope tha this help you. |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
Closing since there as been no follow up since Nick's response. Please let us know if that was not the right thing to do. |
I can't figure out how to get the
Napi::Function&
constructor of an object. I would like to use InstanceOf (https://github.com/nodejs/node-addon-api/blob/main/doc/object.md#instanceof)It looks like a constructor is extracted from an object using Napi::Type::Type, like in https://github.com/nodejs/node-addon-api/blob/main/doc/function.md#constructor, but when I use Napi::Date::Date, I get the following problem:
I don't know much about c++ by the way
The text was updated successfully, but these errors were encountered: