Javascript 使用:在函数回调原型中/在回调函数中传递数组

发布于 2024-11-26 20:42:55 字数 272 浏览 2 评论 0原文

我正在尝试使用公共 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め七分饶幸 2024-12-03 20:42:55

我假设您的实际代码中没有缺少 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文