Napi::FunctionReference is a subclass of Napi::Reference, and
is equivalent to an instance of Napi::Reference<Napi::Function>. This means
that a Napi::FunctionReference holds a Napi::Function, and a
count of the number of references to that Napi::Function. When the count is
greater than 0, a Napi::FunctionReference is not eligible for garbage collection.
This ensures that the Function will remain accessible, even if the original
reference to it is no longer available.
Napi::FunctionReference allows the referenced JavaScript function object to be
called from a native add-on with two different methods: Call and MakeCallback.
See the documentation for Napi::Function for when Call should
be used instead of MakeCallback and vice-versa.
The Napi::FunctionReference class inherits its behavior from the Napi::Reference
class (for more info see: Napi::Reference).
Creates a "weak" reference to the value, in that the initial reference count is set to 0.
static FunctionReference Weak(const Function& value);[in] value: The value which is to be referenced.
Returns the newly created reference.
Creates a "persistent" reference to the value, in that the initial reference count is set to 1.
static FunctionReference Persistent(const Function& value);[in] value: The value which is to be referenced.
Returns the newly created reference.
Creates a new empty instance of Napi::FunctionReference.
FunctionReference();Creates a new instance of the Napi::FunctionReference.
FunctionReference(napi_env env, napi_ref ref);[in] env: The environment in which to construct theNapi::FunctionReferenceobject.[in] ref: The N-API reference to be held by theNapi::FunctionReference.
Returns a newly created Napi::FunctionReference object.
Constructs a new instance by calling the constructor held by this reference.
Napi::Object New(const std::initializer_list<napi_value>& args) const;[in] args: Initializer list of JavaScript values asnapi_valuerepresenting the arguments of the contructor function.
Returns a new JavaScript object.
Constructs a new instance by calling the constructor held by this reference.
Napi::Object New(const std::vector<napi_value>& args) const;[in] args: Vector of JavaScript values asnapi_valuerepresenting the arguments of the constructor function.
Returns a new JavaScript object.
Calls a referenced Javascript function from a native add-on.
Napi::Value Call(const std::initializer_list<napi_value>& args) const;[in] args: Initializer list of JavaScript values asnapi_valuerepresenting the arguments of the referenced function.
Returns a Napi::Value representing the JavaScript object returned by the referenced
function.
Calls a referenced Javascript function from a native add-on.
Napi::Value Call(const std::vector<napi_value>& args) const;[in] args: Vector of JavaScript values asnapi_valuerepresenting the arguments of the referenced function.
Returns a Napi::Value representing the JavaScript object returned by the referenced
function.
Calls a referenced Javascript function from a native add-on.
Napi::Value Call(napi_value recv, const std::initializer_list<napi_value>& args) const;[in] recv: Thethisobject passed to the referenced function when it's called.[in] args: Initializer list of JavaScript values asnapi_valuerepresenting the arguments of the referenced function.
Returns a Napi::Value representing the JavaScript object returned by the referenced
function.
Calls a referenced Javascript function from a native add-on.
Napi::Value Call(napi_value recv, const std::vector<napi_value>& args) const;[in] recv: Thethisobject passed to the referenced function when it's called.[in] args: Vector of JavaScript values asnapi_valuerepresenting the arguments of the referenced function.
Returns a Napi::Value representing the JavaScript object returned by the referenced
function.
Calls a referenced Javascript function from a native add-on after an asynchronous operation.
Napi::Value MakeCallback(napi_value recv, const std::initializer_list<napi_value>& args) const;[in] recv: Thethisobject passed to the referenced function when it's called.[in] args: Initializer list of JavaScript values asnapi_valuerepresenting the arguments of the referenced function.
Returns a Napi::Value representing the JavaScript object returned by the referenced
function.
Calls a referenced Javascript function from a native add-on after an asynchronous operation.
Napi::Value MakeCallback(napi_value recv, const std::vector<napi_value>& args) const;[in] recv: Thethisobject passed to the referenced function when it's called.[in] args: Vector of JavaScript values asnapi_valuerepresenting the arguments of the referenced function.
Returns a Napi::Value representing the JavaScript object returned by the referenced
function.
Napi::Value operator ()(const std::initializer_list<napi_value>& args) const;[in] args: Initializer list of reference to JavaScript values asnapi_value
Returns a Napi::Value representing the JavaScript value returned by the referenced
function.