1. function deepClone(obj, hash = new WeakMap()) {
    2. if (obj === null) return obj
    3. if (obj instanceof Date) return new Date(obj)
    4. if (obj instanceof RegExp) return new RegExp(obj)
    5. if (typeof obj !== 'object') return obj
    6. if (hash.get(obj)) return hash.get(obj)
    7. let newObj = new obj.constructor()
    8. hash.set(obj, newObj)
    9. for (let key of Object.keys(obj)) {
    10. newObj[key] = deepClone(obj[key], hash)
    11. }
    12. return newObj
    13. }