Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a JavaScript function named `call` from dart

Is there any way to call a JavaScript function named call() (in a nested object) from Dart or do I have to wait for Dart 2.0 from which the special handling of call() might get removed?

I have a JS Proxy like:

@JS()
class SomethingFancy {
  external String call();
}

But as call() can be used to turn an object into a function, it makes it impossible to access the function of the JS object.

If I could, I would change the name of the method in Dart, but that's not supported by package:js:

/// By default the dart name is used. It is not valid to specify a custom     
/// [name] for class instance members.

The error I get is:

Uncaught Error: NoSuchMethodError: method not found: 'call$0' (J.getSomethingFancy$1$x(...).call$0 is not a function)

If the function didn't exist, the error would look like this:

Uncaught Error: NoSuchMethodError: method not found: 'callMe' (receiver.callMe is not a function)

Other functions on the same object work just fine.

like image 607
Dennis Kaselow Avatar asked Dec 05 '17 16:12

Dennis Kaselow


1 Answers

You can prefix call with JS$:

@JS()
class SomethingFancy {
  external String JS$call();
}

JS$ can be used as prefix to allow to access to JS names that conflicts with dart keywords.

like image 80
Alexandre Ardhuin Avatar answered Sep 29 '22 04:09

Alexandre Ardhuin