Eduardo Copat
Eduardo Copat

Reputation: 5151

How to define a method for the class 'Proxy' in Dart js-interop?

I'm currently calling a jQuery based plugin called Bootstrap Context Menu.

In order to call it, I need to use the Javascript Interop library. But when I call a jQuery method from it I receive the following warning:

The method 'jQuery' is not defined for the class 'Proxy'

Code snippet:

  js.scoped(() {
    js.context.jQuery('#canvas').contextmenu();
  });

This was not happening before some dart/js-interop updates. What is the right way to get rid of this warning?

Upvotes: 3

Views: 480

Answers (1)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76353

You get this warning because the new analyzer doesn't seem to be aware of the option Report 'no such member' warnings when class defines noSuchMethod() ( Reported at http://dartbug.com/10016 ). If you switch back to the legacy analyzer you shouldn't see this warning anymore.

That said if you want to use the new analyzer and get rid of this warning you can use the array notation like this :

js.context["jQuery"]('#canvas')["contextmenu"]();

But :

  • it's less readable particullary for method calls.
  • it's less efficient for method calls because 2 operations are done ( f = js.context["jQuery"] followed by f('#canvas') ) instead of 1 ( js.context.jQuery('#canvas') )

Upvotes: 4

Related Questions