functiondeepClone(initalObj, finalObj) { var obj = finalObj || {};for(var iininitalObj) { var prop = initalObj[i]; // 避免相互引用对象导致死循环,如initalObj.a = initalObj的情况if(prop === obj) {continue; }if(typeof prop ==='object') { obj[i] = (prop.constructor === Array) ? [] : {}; arguments.callee(prop, obj[i]); }else{ obj[i] = prop; } }returnobj;}var str = {};var obj = { a: {a:"hello", b: 21} };deepClone(obj, str);console.log(str.a);
网友评论