Mercurial > kallithea
changeset 4161:f51578556bc2 rhodecode-2.2.5-gpl
rhodecode.js: implement array.filter for backward compatibility
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Compatibility
under MIT license / public domain
https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 02 Jul 2014 19:03:26 -0400 |
parents | 4451b2eabf64 |
children | a1b80a0a3e15 |
files | rhodecode/public/js/rhodecode.js |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/public/js/rhodecode.js Wed Jul 02 19:03:26 2014 -0400 +++ b/rhodecode/public/js/rhodecode.js Wed Jul 02 19:03:26 2014 -0400 @@ -70,6 +70,45 @@ }; } +/* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Compatibility + under MIT license / public domain, see + https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses */ +if (!Array.prototype.filter) +{ + Array.prototype.filter = function(fun /*, thisArg */) + { + "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 = []; + var thisArg = arguments.length >= 2 ? arguments[1] : void 0; + for (var i = 0; i < len; i++) + { + if (i in t) + { + var val = t[i]; + + // NOTE: Technically this should Object.defineProperty at + // the next index, as push can be affected by + // properties on Object.prototype and Array.prototype. + // But that method's new, and collisions should be + // rare, so use the more-compatible alternative. + if (fun.call(thisArg, val, i, t)) + res.push(val); + } + } + + return res; + }; +} + /** * A customized version of PyRoutes.JS from https://pypi.python.org/pypi/pyroutes.js/ * which is copyright Stephane Klein and was made available under the BSD License.