Created
July 18, 2018 12:23
-
-
Save huafu/a63fef2bb7dbd3d59e129fd990159853 to your computer and use it in GitHub Desktop.
JavaScript real object clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function clone<T>(base: T): T { | |
const res = Object.create(base.constructor.prototype) | |
Object.defineProperties(res, Object.getOwnPropertyDescriptors(base)) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment