cantera
cantera

Reputation: 24995

Pass Argument to Named Iteratee in Underscore .each

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

Answers (1)

user229044
user229044

Reputation: 239291

Yes, you just pass the function without invoking it:

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

Upvotes: 2

Related Questions