4 ms·
The post is a bit misleading. The "native" map method is only Javascript 1.6, so it isn't universally available.
by intellectronica 16y ago
The post is a bit misleading. The "native" map method is only Javascript 1.6, so it isn't universally available.
- mrspeaker 16y ago"Reducing map: A short look at the similarities between the map functionality of jQuery 1.2+ inline map, jQuery 1.3.2 global map and JavaScipts 1.6+ native map function" didn't fit. But if you're unfortunate enough to have to care about the ol' stuff, there are some nice polyfills on each of the MDC map/reduce/filter/etc pages: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map#Compatibility https://developer.mozilla.org/en/JavaScript/Reference/Global...
- dstein 16y agoYou 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; }; }
- Sidnicious 16y agoI'm a big fan of es5-shim (https://github.com/kriskowal/es5-shim/ https://github.com/kriskowal/es5-shim/), which monkey-patches these handy methods in older browsers.