Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 8 years ago by Thomas Bachem

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.

comment:2 Changed 8 years ago by bill

Resolution: wontfix
Status: newclosed

As mentioned in #13468, [24328] removed the webkit special path from that file. And since there's code depending on the current behavior of those array functions we don't want to change their API (especially not before 2.0). Thus, marking this as wontfix.

comment:3 Changed 8 years ago by Thomas Bachem

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.