From f0a89db62ff253fd038e68517e6c508bff22d21b Mon Sep 17 00:00:00 2001 From: nempoBu4 Date: Thu, 8 Oct 2020 19:10:02 +0600 Subject: [PATCH 1/3] Fixed example in addon.md. --- doc/addon.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/addon.md b/doc/addon.md index ee85e7d5e..cccdb63c5 100644 --- a/doc/addon.md +++ b/doc/addon.md @@ -42,8 +42,8 @@ class ExampleAddon : public Napi::Addon { // We can also attach plain objects to `exports`, and instance methods as // properties of those sub-objects. InstanceValue("subObject", DefineProperties(Napi::Object::New(), { - InstanceMethod("decrement", &ExampleAddon::Decrement - })), napi_enumerable) + InstanceMethod("decrement", &ExampleAddon::Decrement) + })) }); } private: From 1fcf880f1876af2af3903e24d9bd2aa3793f8047 Mon Sep 17 00:00:00 2001 From: nempoBu4 Date: Thu, 8 Oct 2020 19:27:17 +0600 Subject: [PATCH 2/3] Added env to Napi::Object::New --- doc/addon.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/addon.md b/doc/addon.md index cccdb63c5..485470f1a 100644 --- a/doc/addon.md +++ b/doc/addon.md @@ -41,7 +41,7 @@ class ExampleAddon : public Napi::Addon { // We can also attach plain objects to `exports`, and instance methods as // properties of those sub-objects. - InstanceValue("subObject", DefineProperties(Napi::Object::New(), { + InstanceValue("subObject", DefineProperties(Napi::Object::New(env), { InstanceMethod("decrement", &ExampleAddon::Decrement) })) }); From aa2107aa74d37a3f94d1e37c57762fb00fd40df7 Mon Sep 17 00:00:00 2001 From: nempoBu4 Date: Sat, 10 Oct 2020 10:37:00 +0600 Subject: [PATCH 3/3] Put back napi_enumerable --- doc/addon.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/addon.md b/doc/addon.md index 485470f1a..26408ae55 100644 --- a/doc/addon.md +++ b/doc/addon.md @@ -43,7 +43,7 @@ class ExampleAddon : public Napi::Addon { // properties of those sub-objects. InstanceValue("subObject", DefineProperties(Napi::Object::New(env), { InstanceMethod("decrement", &ExampleAddon::Decrement) - })) + }), napi_enumerable) }); } private: @@ -80,7 +80,7 @@ The above code can be used from JavaScript as follows: const exampleAddon = require('bindings')('example_addon'); console.log(exampleAddon.increment()); // prints 43 console.log(exampleAddon.increment()); // prints 44 -consnole.log(exampleAddon.subObject.decrement()); // prints 43 +console.log(exampleAddon.subObject.decrement()); // prints 43 ``` When Node.js loads an instance of the add-on, a new instance of the class is