Skip to content

Commit

Permalink
Add array map function for IE9.
Browse files Browse the repository at this point in the history
  • Loading branch information
kanaka committed Feb 14, 2012
1 parent 1af3e54 commit 32f135d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions include/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ Array.prototype.push32 = function (num) {
(num ) & 0xFF );
};

// IE does not support map (even in IE9)
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.map)
{
Array.prototype.map = function(fun /*, thisp*/)
{
var len = this.length;
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 this)
res[i] = fun.call(thisp, this[i], i, this);
}

return res;
};
}

/*
* ------------------------------------------------------
* Namespaced in Util
Expand Down

0 comments on commit 32f135d

Please sign in to comment.