#13467 closed defect (wontfix)
dojo.forEach() doesn't match native behaviour with empty first argument
Reported by: | Thomas Bachem | Owned by: | |
---|---|---|---|
Priority: | high | Milestone: | tbd |
Component: | General | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Doing
dojo.forEach(null, function() { });
works without throwing an error, while
Array.prototype.forEach.call(null, function() { })
does not (at least not in Google Chrome 13).
I realized this when using the WebKit? Mobile build in place of the normal build, which uses the native Array.forEach implementation like shown above.
Changing dojo/_base/array.js around line 123 from
// match the behavior of the built-in forEach WRT empty arrs if(!arr || !arr.length){ return; }
to
// match the behavior of the built-in forEach WRT empty arrs if(!arr.length){ return; }
would align the behaviours.
Change History (3)
comment:1 Changed 10 years ago by
comment:2 Changed 9 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:3 Changed 9 years ago by
A note in the documentation/docblock of dojo.forEach() would be nice nonetheless, as it claims to match the native behaviour.
Note: See
TracTickets for help on using
tickets.
Regarding #13468, it may perhaps be better to deviate from the native behaviour of Array.forEach() and make dojo.forEach() always ignore an empty first argument, even in WebKit? Mobile builds.