add JS implementation for forEach

This commit is contained in:
Fabian Jakobs 2010-12-15 17:33:32 +01:00
commit b817889ad8

View file

@ -87,6 +87,26 @@ if (!Array.prototype.indexOf)
};
}
// from MDC
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fun /*, thisp */) {
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 thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t)
fun.call(thisp, t[i], i, t);
}
};
}
/**
* Retrieves the list of keys on an object.
*/
@ -102,7 +122,7 @@ if (!Object.keys) {
};
}
if (!Function.prototype.bind) {
if (!Function.prototype.bind) {
// from MDC
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
Function.prototype.bind = function (obj) {