var cat = {
name :'mini',
eat: function(){
console.log('fish');
},
cute: {
s:'miaomiao'
},
un: undefined
}
function deepClone(obj) {
let valClone = Array.isArray(obj) ? [] : {};
for(let key in obj) {
if(obj.hasOwnProperty(key)) {
if(typeof obj[key] === 'object' && obj[key]) {
valClone[key] = deepClone(obj[key])
} else {
valClone[key] = obj[key]
}
}
}
return valClone
}
网友评论