Struct napi::bindgen_prelude::JsFunction [−][src]
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.