Closure call with mismatched arguments: function 'call'

 ̄綄美尐妖づ 提交于 2019-12-08 13:11:20

问题


I'm using the (2.0)js-interop library in combination with the JS library ImageLoaded and I'm stuck the FunctionProxy class because the code below throw the foolowing error:

Breaking on exception: Closure call with mismatched arguments: function 'call'

js.FunctionProxy loaded = new js.FunctionProxy((){
      print("called");
      js.Proxy pckry = new js.Proxy(context.Packery, container, options);
    });

js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);

Wich is weird because my js callback is called 5 times before the app crashes.


回答1:


Looking at the Usage section of imagesLoaded it looks like the callback takes one parameter. So you have to add this parameter to your callback :

js.FunctionProxy loaded = new js.FunctionProxy((instance) {
  print("called");
  js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});

js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);

Additional notes :

  • You can avoid new js.FunctionProxy. There are only a limited number of cases where it's needed and your case here is not one of them.
  • imagesLoaded can be use as a function and it simplifies the code.

Thus, you should be able to use :

final img = context.imagesLoaded(container, (instance) {
  print("called");
  js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});


来源:https://stackoverflow.com/questions/20049766/closure-call-with-mismatched-arguments-function-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!