实现了深度复制对象,但是如何限制类型呢?functionisClass(o){if(o===undefined){return"Undefined";}else{returnObject.prototype.toString.call(o).slice(8,-1);}}functioncloneObject(src){varresult,oClass=isClass(src);if(oClass==="Object"){result={};}elseif(oClass==="Array"){result=[];}else{returnsrc;}for(keyinsrc){varcopy=src[key];if(isClass(copy)=="Object"||"Array"){result[key]=arguments.callee(copy);}else{result[key]=src[key];}}returnresult;}
Qyouu
相关分类