napi_get_cb_info


napi_status napi_get_cb_info(napi_env env,
                             napi_callback_info cbinfo,
                             size_t* argc,
                             napi_value* argv,
                             napi_value* thisArg,
                             void** data) 
  • [in] env:调用该 API 时所处的环境。
  • [in] cbinfo:传递给回调函数的回调信息。
  • [in-out] argc:指定提供的 argv 数组的长度,并接收实际的参数数量。argc 可以通过传递 NULL 来选择性地忽略。
  • [out] argv:要将参数复制到其中的 napi_value C 数组。如果参数数量多于提供的数量,则仅复制请求数量的参数。如果提供的参数少于声明的数量,其余的 argv 将填充表示 undefinednapi_value 值。通过传递 NULL 可以选择忽略 argv
  • [out] thisArg:接收调用的 JavaScript this 参数。通过传递 NULL 可以选择忽略 thisArg
  • [out] data:接收回调的数据指针。可以通过传入 NULL 来选择性地忽略 data

如果 API 成功,则返回 napi_ok

【Returns napi_ok if the API succeeded.】

此方法在回调函数中使用,用于从给定的回调信息中检索关于调用的详细信息,如参数和 this 指针。

【This method is used within a callback function to retrieve details about the call like the arguments and the this pointer from a given callback info.】