JS中回调函数的使用

<!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>
原文地址:https://www.cnblogs.com/hwgok/p/5721742.html