-
Notifications
You must be signed in to change notification settings - Fork 465
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
In the properties parameter of the DefineClass(...)
function, the last item is not registered.
#1623
Comments
Would you mind sharing a minimum reproducible setup, and sharing your environment information like Node.js version and platforms? Thank you! |
Node All code here #include <napi.h>
class Device : public Napi::ObjectWrap<Device>
{
public:
static void Initialize(Napi::Env env, Napi::Object exports);
Device(const Napi::CallbackInfo& info);
~Device();
private:
Napi::Value Connect(const Napi::CallbackInfo& info);
Napi::Value Disconnect(const Napi::CallbackInfo& info);
Napi::Value Beep(const Napi::CallbackInfo& info);
Napi::Value Beep1(const Napi::CallbackInfo& info);
};
void Device::Initialize(Napi::Env env, Napi::Object exports)
{
std::vector<Napi::ClassPropertyDescriptor<Device>> properties =
{
InstanceMethod("connect", &Device::Connect),
InstanceMethod("disconnect", &Device::Disconnect),
InstanceMethod("beep", &Device::Beep),
InstanceMethod("beep1", &Device::Beep1), // undefined
};
Napi::Function constructorFunction = DefineClass(env, "MyDevice", properties);
Napi::FunctionReference *constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(constructorFunction);
env.SetInstanceData(constructor);
exports.Set("MyDevice", constructorFunction);
}
Device::Device(const Napi::CallbackInfo &info)
: Napi::ObjectWrap<Device>(info)
{
}
Device::~Device()
{
}
Napi::Value Device::Connect(const Napi::CallbackInfo &info)
{
return info.Env().Undefined();
}
Napi::Value Device::Disconnect(const Napi::CallbackInfo &info)
{
return info.Env().Undefined();
}
Napi::Value Device::Beep(const Napi::CallbackInfo &info)
{
return info.Env().Undefined();
}
Napi::Value Device::Beep1(const Napi::CallbackInfo &info)
{
return info.Env().Undefined();
}
Napi::Object Initialize(Napi::Env env, Napi::Object exports)
{
// Add Device module exports
Device::Initialize(env, exports);
return exports;
}
NODE_API_MODULE(mydevice, Initialize) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created an object using the following code
I can't see
beep1
in JavaScript environment. Is this correct?The text was updated successfully, but these errors were encountered: