<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script src="jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">

function each(data,callback){

//判断传递进来的回调函数是否真的是回调函数

callback = typeof callback == 'function' ? callback : false;

//遍历传递进来的数据 两种情况 一是数组格式 二是对象格式

//1.判断数据是否为数组或者是否有length属性

if(data && data.length!==undefined){

for(var i = 0; i<data.length; i++){

//console.log(i+'=='+data[i])

//console.log(data[i])
if(callback) callback.call(data[i],i,data[i])

}

}else{

for(var i in data){

//console.log(i+'=='+data[i])

if(callback) callback.call(data[i],i,data[i])

}

}

//console.log(data.length)



}


$.each({a:1,b:2},function(index,value){

console.log(this)

return 666
});


</script>
</html>