51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

js进行深拷贝

共夸不受污泥染,没有污泥哪有莲。------《赏荷》

对象深拷贝

|------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | hljs javascript export function deepClone (data) { var type = getObjType(data) var obj if (type === 'array') { obj = [] } else if (type === 'object') { obj = {} } else { // 不再具有下一层次 return data } if (type === 'array') { for (var i = 0, len = data.length; i < len; i++) { data[i] = (function () { if (data[i] === 0) { return data[i] } return data[i] }()) delete data[i].$parent obj.push(deepClone(data[i])) } } else if (type === 'object') { for (var key in data) { delete data.$parent obj[key] = deepClone(data[key]) } } return obj }; |

赞(0)
未经允许不得转载:工具盒子 » js进行深拷贝