首页 > 代码库 > js双向绑定和地址传递带来的痛苦解决方案之对象拷贝

js双向绑定和地址传递带来的痛苦解决方案之对象拷贝

function cloneObj(obj) {
var newObj = {};
if (obj instanceof Array) {
newObj = [];
}
for (var key in obj) {
var val = obj[key];
newObj[key] = typeof val === ‘object‘ ? cloneObj(val): val;
}
return newObj;
};

js双向绑定和地址传递带来的痛苦解决方案之对象拷贝