javascript - array.map function not supported in IE8 standards? -
i don't have ie8 testing ie8 within ie10. when switch "ie8 standards" document mode, javascript map function of array object gives javascript error: object doesn't support property or method 'map'
but when switch "standards" document mode, there's no error. mode should test under?
if ie8 doesn't support map function, there way emulate it?
it's not supported, mdn provides shim close specification:
// production steps of ecma-262, edition 5, 15.4.4.19 // reference: http://es5.github.com/#x15.4.4.19 if (!array.prototype.map) { array.prototype.map = function(callback, thisarg) { var t, a, k; if (this == null) { throw new typeerror(" null or not defined"); } // 1. let o result of calling toobject passing |this| value argument. var o = object(this); // 2. let lenvalue result of calling internal method of o argument "length". // 3. let len touint32(lenvalue). var len = o.length >>> 0; // 4. if iscallable(callback) false, throw typeerror exception. // see: http://es5.github.com/#x9.11 if (typeof callback !== "function") { throw new typeerror(callback + " not function"); } // 5. if thisarg supplied, let t thisarg; else let t undefined. if (thisarg) { t = thisarg; } // 6. let a new array created if expression new array(len) array // standard built-in constructor name , len value of len. = new array(len); // 7. let k 0 k = 0; // 8. repeat, while k < len while(k < len) { var kvalue, mappedvalue; // a. let pk tostring(k). // implicit lhs operands of in operator // b. let kpresent result of calling hasproperty internal method of o argument pk. // step can combined c // c. if kpresent true, if (k in o) { // i. let kvalue result of calling internal method of o argument pk. kvalue = o[ k ]; // ii. let mappedvalue result of calling call internal method of callback // t value , argument list containing kvalue, k, , o. mappedvalue = callback.call(t, kvalue, k, o); // iii. call defineownproperty internal method of arguments // pk, property descriptor {value: mappedvalue, : true, enumerable: true, configurable: true}, // , false. // in browsers support object.defineproperty, use following: // object.defineproperty(a, pk, { value: mappedvalue, writable: true, enumerable: true, configurable: true }); // best browser support, use following: a[ k ] = mappedvalue; } // d. increase k 1. k++; } // 9. return return a; }; }
Comments
Post a Comment