//深克隆 var obj={name:'hlj',age:10,info:{sex:'女',height:'10cm'}}; console.log(obj); var deepCopy=function(source){ var result={}; for(var key in source){ if(typeof(source[key])==='object'){ result[key]=deepCopy(source[key]); }else{ result[key]=source[key]; } } return result; } var obj1=deepCopy(obj); console.log(obj1); //浅克隆 var obj = {name:'wsscat',age:0}; var obj2 = obj; obj2['c'] = 5; console.log(obj); console.log(obj2);
深克隆,浅克隆
最新推荐文章于 2024-03-14 13:00:00 发布