为什么这个array.filter总是不返回任何内容
Why does this array.filter always return nothing?
为什么这个过滤器从不返回任何对象?
NewHashMap.prototype.remove = function (keys, obj) {
// snip
var myEntries = this.entries;
var filteredEntries = myEntries.filter(
function(entry){
//me.isContainedBy(entry, keys) &&
//entry.obj === obj
true;
});
console.debug("entries ", myEntries.length);
console.debug("filtered ", filteredEntries.length);
// snip
}
再进一步,我在不同的上下文中使用它,它是有效的
您还可以看到,我注释掉了实际的过滤器要求,并用一个简单的True替换了它们。同样的事情。
我猜这是一个上下文问题,但我不知道在哪里。
您的true
不会执行任何操作,除非您从匿名函数中return
var filteredEntries = myEntries.filter(
function(entry){
//me.isContainedBy(entry, keys) &&
//entry.obj === obj
return true;
});
或者使用您的实际过滤代码:
var filteredEntries = myEntries.filter(
function(entry){
return me.isContainedBy(entry, keys) && entry.obj === obj
});
您需要从回调函数中return
一个布尔值:
var filteredEntries = myEntries.filter(
function(entry){
//me.isContainedBy(entry, keys) &&
//entry.obj === obj
return true;
});
相关文章:
- AJAX:$_GET不返回任何值
- document.styleSheets不返回任何内容
- 在解析对象.save()中;没有返回任何原因
- PhantomJs在控制台中发出http请求时不会返回任何状态
- 为什么这个array.filter总是不返回任何内容
- 是否有任何内置方法可以更改JavaScript对象'的属性设置为某个值
- 返回$http内的父函数
- IE8DOM转换XML,并且不从jQueryfind()或filter()返回任何内容
- 比较数组中的连续元素不会返回任何结果(javascript)
- WebKitBrowser.StringByEvaluatingJavaScriptFromString 不返回任何值
- Ajax 不返回任何结果
- 我的 API 调用没有返回任何内容
- Javascript函数img.onload不返回任何内容(真或假)
- 为什么我的 sinon 假服务器不返回任何内容
- beforeSave导致查询不返回任何内容
- Ajax对PHP页面的调用总是不返回任何内容,即使PHP页面有回声
- 控制器的Helper函数不返回任何内容
- 函数不返回任何内容
- Breeze.js getEntities不返回任何实体
- 自定义Angular.js过滤器在IE8中不返回任何内容,在Chrome/FF中运行良好