js使用递归函数深拷贝对象
/**
* @description: 深拷贝
* @param {*} source原对象
* @return {*}
*/
function cloneDeep(source) {
// target目标对象
var target = {};
for(var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
if (typeof source[key] === 'object') {
target[key] = cloneDeep(source[key]); // 注意这里
} else {
target[key] = source[key];
}
}
}
return target;
}