napi_unwrap
napi_status napi_unwrap(napi_env env,
napi_value js_object,
void** result); [in] env:调用该 API 时所处的环境。[in] js_object:与本地实例关联的对象。[out] result:指向封装的原生实例的指针。
如果 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.】