This project is archived and is in readonly mode.

#857 ✓resolved
Chris Buckley

$each(undefined, ...) operates on window

Reported by Chris Buckley | February 25th, 2010 @ 12:10 PM | in 1.3.0 rc2 (closed)

(The same bug occurs with null instead of undefined.)

Example code:

$each(undefined, console.log);
// or, cutting out the middle men:
Hash.forEach(undefined, console.log);

Expected:

Nothing happens, like with Array.forEach.

Actual:

Properties of the window are logged.

The bug happens because calling Hash.forEach like above uses Native.genericize to call the prototype method with the first parameter (undefined) as the bind value. This results in the prototype being called via Function.apply.

I don't know how other browsers treat it, but MDC says that if the first parameter to apply is undefined or null, it defaults to the global object. So Hash.forEach operates on the window.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Referenced by

Pages