Array.forEach() et al with additional parameters

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Dec 22 05:29:53 PST 2014


if you don't need a context, you can simply use it to pass anything you
want.

as example, instead of this

On Sat, Dec 20, 2014 at 12:12 PM, Christian Mayer <mail at christianmayer.de>
wrote:
>
>
> [1,2,3].forEach( myCallback, undefined, 'additionalFoo' );
>
>
you could do this:

[1,2,3].forEach( callback, ['additionalFoo']);

and callback will look like

function callback( element, count, array )
{
  myCallback.apply(nulll, element, count, array.concat(this));
}

In this way you can prepend, append, swap index, use just what you need ...
etc ... I don't think it can be simplified any better with yet another
change to the Array API

Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141222/cbb0c618/attachment.html>


More information about the es-discuss mailing list