6

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Does this work with DDC? It complains JS$call is not a function, but Dart2JS does not. I remember seeing JS$JS$ also means something but I can't find it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.