IE8 及以前没有 forEach,核心 polyfill:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (callback, thisArg) {
var O = Object(this);
var len = O.length >>> 0;
var k = 0;
while (k < len) {
if (k in O) {
callback.call(thisArg, O[k], k, O);
}
k++;
}
};
}
注意:jQuery 的 each 方法回调参数顺序与 forEach 相反——先 index 后 elem。