Array extras and Objects

Andrea Giammarchi andrea.giammarchi at
Wed Nov 30 23:47:09 PST 2011

Let's say this is an attempt to bring some new, easy to implement, method
for the native Object.prototype
Specially about forEach, the most used Array.prototype method out there,
it's quite clear JS developers would like to have similar method to iterate
over objects, as key:value pairs rather than index:value.

Almost every framework/library out there has an "error prone" each(obj,
callback) method, able to automagically recognize if the passed obj is an
array, an arrayLike, or an object.
A classic failing scenario is a function used as object, where the length
property won't mean it's an arrayLike entity.

As summary, I wonder if this proposal could make things more explicit, easy
to remember, and faster, if implemented natively:

where more details about the "why" and "how", through examples, are
explained in my post:

The quick version, and all I am asking is an opinion about this, is

obj.forEach(function (value, key, original) {
  // all true conditions
  value === original[key];
  original === obj;
  this === optionalContext;
}, optionalContext);

Thanks for any sort of feedback.

Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list