@@ -4720,14 +4720,15 @@ napi_status napi_define_class(napi_env env,
4720
4720
```
4721
4721
4722
4722
* `[in] env`: The environment that the API is invoked under.
4723
- * `[in] utf8name`: Name of the JavaScript constructor function; this is
4724
- not required to be the same as the C++ class name, though it is recommended
4725
- for clarity .
4723
+ * `[in] utf8name`: Name of the JavaScript constructor function; When wrapping a
4724
+ C++ class, we recommend for clarity that this name be the same as that of
4725
+ the C++ class .
4726
4726
* `[in] length`: The length of the `utf8name` in bytes, or `NAPI_AUTO_LENGTH`
4727
4727
if it is null-terminated.
4728
4728
* `[in] constructor`: Callback function that handles constructing instances
4729
- of the class. This should be a static method on the class, not an actual
4730
- C++ constructor function. [`napi_callback`][] provides more details.
4729
+ of the class. When wrapping a C++ class, this method must be a static member
4730
+ with the [`napi_callback`][] signature. A C++ class constructor cannot be
4731
+ used. [`napi_callback`][] provides more details.
4731
4732
* `[in] data`: Optional data to be passed to the constructor callback as
4732
4733
the `data` property of the callback info.
4733
4734
* `[in] property_count`: Number of items in the `properties` array argument.
@@ -4739,27 +4740,33 @@ napi_status napi_define_class(napi_env env,
4739
4740
4740
4741
Returns `napi_ok` if the API succeeded.
4741
4742
4742
- Defines a JavaScript class that corresponds to a C++ class, including:
4743
-
4744
- * A JavaScript constructor function that has the class name and invokes the
4745
- provided C++ constructor callback.
4746
- * Properties on the constructor function corresponding to _static_ data
4747
- properties, accessors, and methods of the C++ class (defined by
4748
- property descriptors with the `napi_static` attribute).
4749
- * Properties on the constructor function's `prototype` object corresponding to
4750
- _non-static_ data properties, accessors, and methods of the C++ class
4751
- (defined by property descriptors without the `napi_static` attribute).
4752
-
4753
- The C++ constructor callback should be a static method on the class that calls
4754
- the actual class constructor, then wraps the new C++ instance in a JavaScript
4755
- object, and returns the wrapper object. See `napi_wrap()` for details.
4743
+ Defines a JavaScript class, including:
4744
+
4745
+ * A JavaScript constructor function that has the class name. When wrapping a
4746
+ corresponding C++ class, the callback passed via `constructor` can be used to
4747
+ instantiate a new C++ class instance, which can then be placed inside the
4748
+ JavaScript object instance being constructed using [`napi_wrap`][].
4749
+ * Properties on the constructor function whose implementation can call
4750
+ corresponding _static_ data properties, accessors, and methods of the C++
4751
+ class (defined by property descriptors with the `napi_static` attribute).
4752
+ * Properties on the constructor function's `prototype` object. When wrapping a
4753
+ C++ class, _non-static_ data properties, accessors, and methods of the C++
4754
+ class can be called from the static functions given in the property
4755
+ descriptors without the `napi_static` attribute after retrieving the C++ class
4756
+ instance placed inside the JavaScript object instance by using
4757
+ [`napi_unwrap`][].
4758
+
4759
+ When wrapping a C++ class, the C++ constructor callback passed via `constructor`
4760
+ should be a static method on the class that calls the actual class constructor,
4761
+ then wraps the new C++ instance in a JavaScript object, and returns the wrapper
4762
+ object. See [`napi_wrap`][] for details.
4756
4763
4757
4764
The JavaScript constructor function returned from [`napi_define_class`][] is
4758
- often saved and used later, to construct new instances of the class from native
4759
- code, and/or check whether provided values are instances of the class. In that
4760
- case, to prevent the function value from being garbage-collected, create a
4761
- persistent reference to it using [`napi_create_reference`][] and ensure the
4762
- reference count is kept >= 1.
4765
+ often saved and used later to construct new instances of the class from native
4766
+ code, and/or to check whether provided values are instances of the class. In
4767
+ that case, to prevent the function value from being garbage-collected, a
4768
+ strong persistent reference to it can be created using
4769
+ [`napi_create_reference`][], ensuring that the reference count is kept >= 1.
4763
4770
4764
4771
Any non-`NULL` data which is passed to this API via the `data` parameter or via
4765
4772
the `data` field of the `napi_property_descriptor` array items can be associated
0 commit comments