本文载入qwrap一个dump的函数设计:
/** *@param {Object} obj *@param {Array} props *@example ObjectH.dump({"name":"zhang","id":1,"age":20},["name","id"]) *返回:{name:"zhangyaochun",id:1} / dump:function(obj,props){ //定义返回值类型 var ret = {}; //支持props为array,进行遍历 for(var i = 0,len = props.length;i<len;i++){ if(i in props){ var key = props[i]; if(key in obj){ //往ret里面装key,obj[key] ret[key] = obj[key]; } } } return ret; }