napi_unwrap
napi_status napi_unwrap(napi_env env,
napi_value js_object,
void** result);
-
[in] env
:调用 API 的环境。¥
[in] env
: The environment that the API is invoked under. -
[in] js_object
:与原生实例关联的对象。¥
[in] js_object
: The object associated with the native instance. -
[out] result
:指向封装的原生实例的指针。¥
[out] result
: Pointer to the wrapped native instance.
如果 API 成功,则返回 napi_ok
。
¥Returns napi_ok
if the API succeeded.
使用 napi_wrap()
检索先前封装在 JavaScript 对象中的原生实例。
¥Retrieves a native instance that was previously wrapped in a JavaScript
object using napi_wrap()
.
当 JavaScript 代码调用类上的方法或属性访问器时,将调用相应的 napi_callback
。如果回调用于实例方法或访问器,则回调的 this
参数是封装器对象;然后可以通过在封装对象上调用 napi_unwrap()
来获得作为调用目标的封装 C++ 实例。
¥When JavaScript code invokes a method or property accessor on the class, the
corresponding napi_callback
is invoked. If the callback is for an instance
method or accessor, then the this
argument to the callback is the wrapper
object; the wrapped C++ instance that is the target of the call can be obtained
then by calling napi_unwrap()
on the wrapper object.