讓ie8支持foreach


  

if ( !Array.prototype.forEach ) {

Array.prototype.forEach = function forEach( callback, thisArg ) {

var T, k;

if ( this == null ) {
throw new TypeError( "this is null or not defined" );
}
var O = Object(this);
var len = O.length >>> 0;
if ( typeof callback !== "function" ) {
throw new TypeError( callback + " is not a function" );
}
if ( arguments.length > 1 ) {
T = thisArg;
}
k = 0;

while( k < len ) {

var kValue;
if ( k in O ) {

kValue = O[ k ];
callback.call( T, kValue, k, O );
}
k++;
}
};
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM