【发布时间】:2015-11-21 14:24:21
【问题描述】:
我有这样的功能:
function contains(needle,haystack) {
return $.each(haystack,function(i,v) {
if(v == needle) {
console.log('true, so return');
return true;
}
if(typeof v == 'object') {
return app.contains(needle,v);
}
console.log('I have not yet returned');
return false;
});
}
当我向其中传递一些东西时(比如说一个长度为 2 的对象,其中一个项目匹配),控制台显示:
true, so return
I have not yet returned
I have not yet returned
这是为什么?我该如何解决?
【问题讨论】:
-
我很困惑。为什么 $.each 前面有一个回报?为什么你的 $.each 回调有回报?
标签: javascript jquery loops