pub struct JsFunction(_);

Implementations

See Working with JavaScript Functions.

Example:

use napi::{JsFunction, CallContext, JsNull, Result};

#[js_function(1)]
pub fn call_function(ctx: CallContext) -> Result<JsNull> {
    let js_func = ctx.get::<JsFunction>(0)?;
    let js_string = ctx.env.create_string("hello".as_ref())?.into_unknown()?;
    js_func.call(None, &[js_string])?;
    Ok(ctx.env.get_null()?)
}

napi_call_function The same with call, but without arguments

https://nodejs.org/api/n-api.html#n_api_napi_new_instance

This method is used to instantiate a new JavaScript value using a given JsFunction that represents the constructor for the object.

Trait Implementations

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.