callAsFunction 方法

  1. @JS('call')
JSAny? callAsFunction(
  1. [JSAny? thisArg,
  2. JSAny? arg1,
  3. JSAny? arg2,
  4. JSAny? arg3,
  5. JSAny? arg4]
)

使用JavaScript的.call语法调用此JSFunction并返回结果。

最多只能传入4个参数以保持与其他API的一致性和相对简洁。如果需要更多参数,可以声明具有相同语法的自定义外部成员。

实现

// We rename this function since declaring a `call` member makes a class
// callable in Dart. This is convenient, but unlike Dart functions, JavaScript
// functions explicitly take a `this` argument (which users can provide `null`
// for in the case where the function doesn't need it), which may lead to
// confusion.
// https://mdn.org.cn/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
@JS('call')
external JSAny? callAsFunction(
    [JSAny? thisArg, JSAny? arg1, JSAny? arg2, JSAny? arg3, JSAny? arg4]);