allowInteropCaptureThis function

Function allowInteropCaptureThis (Function f)

Returns a wrapper around function f that can be called from JavaScript using package:js JavaScript interop, passing JavaScript this as the first argument.

See allowInterop.

When called from Dart, null will be passed as the first argument.

Implementation

Function allowInteropCaptureThis(Function f) {
  if (JS('bool', 'typeof(#) == "function"', f)) {
    // Behavior when the function is already a JS function is unspecified.
    throw ArgumentError(
        "Function is already a JS function so cannot capture this.");
    return f;
  } else {
    return _convertDartFunctionFastCaptureThis(f);
  }
}