<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> Array.prototype.each = function(callback){ if(typeof callback === ‘function‘){ for(var i=0;i<this.length;i++){ callback(i,this[i]); } } }; var arr = ["1",‘a‘,‘g‘]; function handler(i,o){ console.log(i+":"+o); } arr.each(function (i, o) { if(i>1){ console.log(o); } }); arr.each(function () { }); </script></head><body> </body></html>
时间: 2024-10-23 13:54:03