【问题标题】:underscore some method giving unexpected result强调一些给出意外结果的方法
【发布时间】:2013-07-13 11:41:45
【问题描述】:

我正在尝试用下划线库中的 _.some 调用替换以下代码

var anyInTopRow = false;

            for (var g = 0; g < this.grid[1].length; g++ ) {
                if (this.grid[1][g] != undefined) {
                    anyInTopRow = true;
                    break;
                }
            }

下划线的 some/any 方法:

var anyInTopRow = _.some(this.grid[1], function(x) {x != undefined;});

但它们使用相同的数据返回不同的结果

我做错了什么?

【问题讨论】:

    标签: javascript underscore.js lodash


    【解决方案1】:

    你没有返回任何东西。试试

    var anyInTopRow = _.some(this.grid[1], function(x) {return x != undefined;});
    

    【讨论】:

    • jshint 或等价物会提醒您注意此类问题:my_script.js: line 1, col 22, Expected an assignment or function call and instead saw an expression.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 2019-03-06
    • 1970-01-01
    • 2015-03-24
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多