深度克隆基本类型函数实现(学习记录)

function deepClone(obj) {
    
    
	let result;
	if (typeof obj === 'object') {
    
    
		result = typeof obj.constructor == Array ? [] : {
    
    }
		for (let i in obj) {
    
    
			result[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
		}
	} else {
    
    
		result = obj
	}
	return result
}

猜你喜欢

转载自blog.csdn.net/qq_40026668/article/details/114284090