function forEach(list, callback){ for(var n = 0; n <list.length; n++){ callback.call(list[n], n); } } var arr = [1,2,3,4,5,6,7,8] forEach(arr, function(index){ if(this == arr[index]){ console.log("Got the expected value of " + arr[index]); } })
分享一个代码片段