下划线 _.each ,有什么方法可以使用命名函数作为迭代器并向其传递参数吗?
parseItems: function() {
return _.each(this.items, this.parseItem(item), this);
}
或者我必须这样做:
parseItems: function() {
return _.each(this.items, function(item) {
this.parseItem(item);
}, this);
}
最佳答案
是的,您只需传递该函数而不调用它:
parseItems: function() {
return _.each(this.items, this.parseItem, this);
}
关于javascript - 将参数传递给 Underscore .each 中的命名 Iteratee,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27597810/