//indexOf实现 // http://webreflection.blogspot.fr/2011/06/partial-polyfills.html function indexOf(value) { for (var i = this.length; i-- && this[i] !== value;) {} return i; } var arr = [0, 1, 2, 3, 4]; indexOf.call(arr, 4);
// each的实现
function each(ary, func) {
if (ary) {
var i;
for (i = 0; i < ary.length; i += 1) {
if (ary[i] && func(ary[i], i, ary)) {
break;
}
}
}
}
var arr = [1,2,3,4]
each(arr, function(value, index) {console.log(value)})