Javascript 使用:在函数回调原型中/在回调函数中传递数组
我正在尝试使用公共 JavaScript 库,其中一个回调函数在文档中定义为对象数组,我期望定义类似
bar(foo) {
alert("Length of object is "+foo.length);
}
我得到的答案 foo 未定义的内容,查看库中的调用代码,回调被调用为
register(event,blah,blah,{foo:foo})
Q。我的回调函数应该是什么样子?
I am trying to use a public JavaScript library one of the callback functions is defined in the documentation as being with an array of objects, I was expecting to define something like
bar(foo) {
alert("Length of object is "+foo.length);
}
I get the answer that foo
is undefined, looking at the calling code in the library, the callback is invoked as
register(event,blah,blah,{foo:foo})
Q. What should my callback function look like ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的实际代码中没有缺少 bar 的
function
关键字:)...猜测回调的参数似乎是一个对象,而不是一个数组。在回调中 console.log(foo) 得到什么?
您确定您实际上正在调用回调吗?您是否尝试过使用函数而不是命名回调函数?
I assume the
function
keyword for bar isn't missing in your actual code :)...At a guess it looks like the parameter for the callback is an object, not an array. What do you get for console.log(foo) in the callback?
Are you sure you're actually calling the callback -- have you tried using a function rather than naming the callback function?