map:function(obj,fn){
var res = []; //map中的返回值res
//是否是数组
if(dQuery.isArray(obj)){
for(var i=0;i < obj.length;i++){
var temp = fn(obj[i],i); //执行回调函数,结果赋值给temp
if(temp){ //jQuery中回调函数有值的时候,才执行此操作,否则结果为空,若不加此判断,就会是undefined
res.push(temp);
}
}
}
//是否是对象
else if(dQuery.isObject(obj)){
for(var key in obj ){
var temp = fn(obj[key],key);
if(temp){
res.push(temp);
}
}
}
return res;
}
//map方法
var arr=[1,2,3,4];
var obj1 = {0:"1",1:"2",2:"3"};
var obj2 = {"name":"g","age":"18"};
var res = $.map(obj2,function(value,key){ //map方法,value在前
//console.log(value,key);
return value;
//return value;
})
console.log(res);