/** * å¤ææ°æ®ç±»å */ function checkType(target) { // typeof -instanceof -toString.call() -Array.isArray() return Object.prototype.toString.call(target).slice(8, -1) } /** * åºäºJsonåºååçæ·±æ·è´ãä¸è½å¤ç彿°ã */ export function DeepCloneByJSON(target) { return JSON.parse(JSON.stringify(target)) } /** * åºäºé彿æ³çæ·±æ·è´ */ export function DeepClone(target) { let result const targetType = checkType(target) if (targetType === 'object') { // å¤ç对象 result = {} } if (targetType === 'Array') { result = [] } // éåç®æ æ°æ® for (const key in target) { // è·åæ¯ä¸é¡¹å¼ const value = target[key] // éå½å¤ç result[key] = DeepClone(value) } return result }