From d8a88c7f47f9d8b233cff6e15a236b250f289c7d Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 25 May 2012 14:49:47 +0200 Subject: [PATCH] add Array.prototype.lastIndexOf --- source/Ox/js/Fallback.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/Ox/js/Fallback.js b/source/Ox/js/Fallback.js index 07e08c9a..2046b5a3 100644 --- a/source/Ox/js/Fallback.js +++ b/source/Ox/js/Fallback.js @@ -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) {