add JS implementation for forEach
This commit is contained in:
parent
ac923b5813
commit
b817889ad8
1 changed files with 21 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue