function deepClone(obj) { if (obj === null) return null; if (typeof obj !== 'object') return obj; if (obj instanceof Date) { let date = new Date(); date.setTime(obj.getTime()); return date; } if (obj instanceof RegExp) { let re = new RegExp(obj.source); re.lastIndex = obj.lastIndex; return re; } let newObj = new obj.constructor(); for (let key in obj) { if (obj.hasOwnProperty(key)) { newObj[key] = deepClone(obj[key]); } } return newObj; }
标签:return,对象,newObj,re,let,key,obj,copy From: https://www.cnblogs.com/panax/p/17533930.html