Open
Description
起因
在做项目的时候发现ie8不兼容Array.prototype.forEach方法,找到了两个解决方案,jquery.each和es5-shim
解决方案
1. jquery.each
$.each(array, function(key, value){
// array[key] === value;
});
2. es5-shim
第二种解决方案是检测是否有这个方法,如果没有,自定义它,es5-shim帮我们做好了这个事情。
安装
bower install es5-shim --save
使用
<script src="./es5-shim.js"></script>
<script src="./es5-sham.js"></script>
// load your script
参考资料:
http://stackoverflow.com/questions/412447/for-each-javascript-support-in-ie