JSObject.makeFunctionWithCallback constructor

JSObject.makeFunctionWithCallback(
  1. JSContext context,
  2. String name,
  3. Pointer<NativeFunction<JSObjectCallAsFunctionCallback>>? callAsFunction
)

Convenience method for creating a JavaScript function with a given callback as its implementation. name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function. callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.

Implementation

JSObject.makeFunctionWithCallback(
    this.context,
    String name,
    Pointer<NativeFunction<JSObjectRef.JSObjectCallAsFunctionCallback>>?
        callAsFunction)
    : this.pointer = JSObjectRef.jSObjectMakeFunctionWithCallback(
          context.pointer,
          JSString.fromString(name).pointer,
          callAsFunction ?? nullptr);