Reputation: 24995
In Underscore _.each, is there any way to use a named function as the iteratee and pass it an argument?
parseItems: function() {
return _.each(this.items, this.parseItem(item), this);
}
Or do I have to do it like this:
parseItems: function() {
return _.each(this.items, function(item) {
this.parseItem(item);
}, this);
}
Upvotes: 0
Views: 294
Reputation: 239291
Yes, you just pass the function without invoking it:
parseItems: function() {
return _.each(this.items, this.parseItem, this);
}
Upvotes: 2