if (!Array.prototype.forEach) {12Array.prototype.forEach = function(callback, thisArg) {34var T, k;56if (this == null) {7throw new TypeError(' this is null or not defined');8}910// 1. Let O be the result of calling ToObject passing the |this| value as the argument.11var O = Object(this);1213// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".14// 3. Let len be ToUint32(lenValue).15var len = O.length >>> 0;1617// 4. If IsCallable(callback) is false, throw a TypeError exception.18// See: http://es5.github.com/#x9.1119if (typeof callback !== "function") {20throw new TypeError(callback + ' is not a function');21}2223// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.24if (arguments.length > 1) {25T = thisArg;26}2728// 6. Let k be 029k = 0;3031// 7. Repeat, while k < len32while (k < len) {3334var kValue;3536// a. Let Pk be ToString(k).37// This is implicit for LHS operands of the in operator38// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.39// This step can be combined with c40// c. If kPresent is true, then41if (k in O) {4243// i. Let kValue be the result of calling the Get internal method of O with argument Pk.44kValue = O[k];4546// ii. Call the Call internal method of callback with T as the this value and47// argument list containing kValue, k, and O.48callback.call(T, kValue, k, O);49}50// d. Increase k by 1.51k++;52}53// 8. return undefined54};55}5657if (!Array.isArray) {58Array.isArray = function(arg) {59return Object.prototype.toString.call(arg) === '[object Array]';60};61}6263if (!Array.prototype.map) {6465Array.prototype.map = function(callback, thisArg) {6667var T, A, k;6869if (this == null) {70throw new TypeError(' this is null or not defined');71}7273// 1. Let O be the result of calling ToObject passing the |this|74// value as the argument.75var O = Object(this);7677// 2. Let lenValue be the result of calling the Get internal78// method of O with the argument "length".79// 3. Let len be ToUint32(lenValue).80var len = O.length >>> 0;8182// 4. If IsCallable(callback) is false, throw a TypeError exception.83// See: http://es5.github.com/#x9.1184if (typeof callback !== 'function') {85throw new TypeError(callback + ' is not a function');86}8788// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.89if (arguments.length > 1) {90T = thisArg;91}9293// 6. Let A be a new array created as if by the expression new Array(len)94// where Array is the standard built-in constructor with that name and95// len is the value of len.96A = new Array(len);9798// 7. Let k be 099k = 0;100101// 8. Repeat, while k < len102while (k < len) {103104var kValue, mappedValue;105106// a. Let Pk be ToString(k).107// This is implicit for LHS operands of the in operator108// b. Let kPresent be the result of calling the HasProperty internal109// method of O with argument Pk.110// This step can be combined with c111// c. If kPresent is true, then112if (k in O) {113114// i. Let kValue be the result of calling the Get internal115// method of O with argument Pk.116kValue = O[k];117118// ii. Let mappedValue be the result of calling the Call internal119// method of callback with T as the this value and argument120// list containing kValue, k, and O.121mappedValue = callback.call(T, kValue, k, O);122123// iii. Call the DefineOwnProperty internal method of A with arguments124// Pk, Property Descriptor125// { Value: mappedValue,126// Writable: true,127// Enumerable: true,128// Configurable: true },129// and false.130131// In browsers that support Object.defineProperty, use the following:132// Object.defineProperty(A, k, {133// value: mappedValue,134// writable: true,135// enumerable: true,136// configurable: true137// });138139// For best browser support, use the following:140A[k] = mappedValue;141}142// d. Increase k by 1.143k++;144}145146// 9. return A147return A;148};149}150151152