2014-12-22 77 views
0

在下劃線_.each中,是否有任何方法將使用命名函數作爲迭代器並將其傳遞給參數?將參數傳遞給下劃線中的被命名的Iteratee。每個

parseItems: function() { 
    return _.each(this.items, this.parseItem(item), this); 
} 

還是我必須做這樣的:

parseItems: function() { 
    return _.each(this.items, function(item) { 
    this.parseItem(item); 
    }, this); 
} 

回答

2

是的,你只是傳遞功能,而不必調用它:

parseItems: function() { 
    return _.each(this.items, this.parseItem, this); 
} 
+0

真棒,謝謝 – cantera