使用不匹配参数的闭包调用:function'call' [英] Closure call with mismatched arguments: function 'call'
问题描述
我使用的是(2.0)js-interop库与JS库的组合 ImageLoaded 我陷入了 FunctionProxy
类,因为下面的代码抛出了以下错误:
异常:使用不匹配参数的Closure调用: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);
这是很奇怪的,因为我的js回调被调用5次之前的应用程序崩溃。
查看使用 rel =nofollow> imagesLoaded 它看起来像回调需要一个参数。所以你必须添加这个参数到你的回调:
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);
其他注意事项:
- 您可以避免
new js.FunctionProxy
。 -
imagesLoaded
可以用作
因此,您应该能够使用:
final img = context.imagesLoaded(container,(instance){
print(called);
js .proxy pckry = new js.Proxy(context.Packery,container,options);
});
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.
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);
});
这篇关于使用不匹配参数的闭包调用:function'call'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!