function clone(o) { var temp = {} for (var key in o) { if (typeof o[key] == 'object') { temp[key] = clone(o[key]) } else { temp[key] = o[key] } } return temp}
测试:
var obj = {qwe:123,asd:456};
var obj1 = obj,obj2 = clone(obj);
obj1.qwe = 456;
obj2.asd = 'asdzxc';
console.log(obj);//{qwe: 456, asd: 456}
console.log(obj1);//{qwe: 456, asd: 456}
console.log(obj2);//{qwe: 123, asd: "asdzxc"}
原文转载:http://www.shaoqun.com/a/691740.html
gem:https://www.ikjzd.com/w/1997
retriever:https://www.ikjzd.com/w/773
functionclone(o){vartemp={}for(varkeyino){if(typeofo[key]=='object'){temp[key]=clone(o[key])}else{temp[key]=o[key]}}returntemp}测试:varobj={qwe:123,asd:456};varobj1=obj,obj2=clone(obj);obj1.qwe=
宝付:https://www.ikjzd.com/w/539
1号店网:https://www.ikjzd.com/w/2263
斑马物流:https://www.ikjzd.com/w/1316
亚马逊索评邮件该怎么写,买家才会留评呢?:https://www.ikjzd.com/home/100860
娱乐圈里"最二"女人排行榜:http://lady.shaoqun.com/m/a/268608.html
特朗普版"水门事件"!通话一小时强行要求重新计票!:https://www.ikjzd.com/home/139297
No comments:
Post a Comment