例如这段,在其他很多地方也是,把i放在外面,而不是放在for里面
grep: function( elems, callback, invert ) {
var callbackInverse,
matches = [],
i = 0,
length = elems.length,
callbackExpect = !invert;
// Go through the array, only saving the items
// that pass the validator function
for ( ; i < length; i++ ) {
callbackInverse = !callback( elems[ i ], i );
if ( callbackInverse !== callbackExpect ) {
matches.push( elems[ i ] );
}
}
return matches;
},
jquery源码这么写到底有啥好处
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…