add Array.prototype.lastIndexOf

This commit is contained in:
rolux 2012-05-25 14:49:47 +02:00
parent 68ff06af2a
commit d8a88c7f47

View file

@ -58,6 +58,26 @@ if (!Array.prototype.indexOf) {
};
}
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
if (!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf = function(val) {
if (this === void 0 || this === null) {
throw new TypeError();
}
var arr = Object(this),
i,
len = arr.length >>> 0,
ret = -1;
for (i = len - 1; i >= 0; i--) {
if (i in arr && arr[i] === val) {
ret = val;
break;
}
}
return ret;
};
}
// see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map
if (!Array.prototype.map) {
Array.prototype.map = function(fn, that) {