

Reducing Map: jQuery vs jQuery vs JavaScript - mrspeaker
http://www.mrspeaker.net/2011/04/27/reducing-map/

======
IgorPartola
Offtopic follows:

One thing that sucks about JS currently is the fact that you have to do
Array.prototype.map.call(a, ...) instead of a.map, and even then you don't
have a guarantee that the correct function will execute. I know in ECMAScript
5 you can freeze properties of an object, but unless prototypes of basic
methods come frozen, it's not ideal.

~~~
brunoc
Why exactly do you have to do that? Because some other unknown party could
have overwritten the prototype with a new map function?

If that's the case, none of the basic objects are safe, not just Array..

~~~
IgorPartola
Right. My point exactly. In most cases this is not a problem and sometimes can
be really nice: like when you want to add some profiling code, etc. However,
this is also pretty terrible when it comes to large code bases or when you see
libraries out there that modify prototypes of base objects.

------
intellectronica
The post is a bit misleading. The "native" map method is only Javascript 1.6,
so it isn't universally available.

~~~
dstein
You can make it universally available with:

    
    
      if (!Array.prototype.map)
      {
    	Array.prototype.map = function(fun /*, thisp */)
    	{
    	  "use strict";
      
    	  if (this === void 0 || this === null)
    		throw new TypeError();
      
    	  var t = Object(this);
    	  var len = t.length >>> 0;
    	  if (typeof fun !== "function")
    		throw new TypeError();
      
    	  var res = new Array(len);
    	  var thisp = arguments[1];
    	  for (var i = 0; i < len; i++)
    	  {
    		if (i in t)
    		  res[i] = fun.call(thisp, t[i], i, t);
    	  }
      
    	  return res;
    	};
      }

------
fharper1961
I had no idea there were 3 different map options available.

Are you going to compare performance?

~~~
PanosJee
I personally use the map functioned defined in Underscore.js

------
Swizec
Also check out the async library by caolan. Primarily designed for node.js,
but also works with client-side. <https://github.com/caolan/async>

It's got the nice feature of providing synchronous and asynchronous maps,
reduces, filters and everything else you'd expect.

