Opened 13 years ago

Closed 13 years ago

#9399 closed enhancement (wontfix)

Alias forEach as each

Reported by: Les Owned by: anonymous
Priority: high Milestone: 1.4
Component: General Version: 1.3.0
Keywords: each, forEach Cc:
Blocked By: Blocking:

Description (last modified by bill)

Enhancement suggestion: alias the forEach method (wherever it's used) as each. This should make the code more compact. Note that both MooTools and jQuery use each().

Change History (3)

comment:1 Changed 13 years ago by bill

Description: modified (diff)

Hmm, according to and, jquery's each() method is like dojo's every() method, in that if/when the callback function returns false, it breaks the loop.

Dojo's forEach() method is different in that it ignores the callback's return value.

Maybe it makes more sense to alias dojo.every to dojo.each, although I'm generally not a fan of aliases.

Note that Dojo's forEach() is named after Array.forEach in javascript.

comment:2 Changed 13 years ago by Les

See the examples below. The jQuery notation is more compact and I'd like to use it in the context of dojo.query

jQuery: $('div').each(function() {

'this' is a DOM element alert(this.tagName);


dojo: (I'd like to use each() for NodeLists? instead of forEach()) dojo.query('div').each(function(node) {



comment:3 Changed 13 years ago by James Burke

Resolution: wontfix
Status: newclosed

jQuery's implementation is not as simple as an alias. jQuery's:

  • assumes "this" in the callback is the node.
  • breaking out of the loop is possible.
  • the index of the loop is the first arg instead of the second arg.

I am hoping we address this with a jquery compatibility module. I am working on one, but no ETA on the arrival.

I am going to close this ticket for now, since a simple alias will not be enough, and hopefully the jquery compat module will fill this need when it goes in.

Note: See TracTickets for help on using tickets.