Skip to content

Instantly share code, notes, and snippets.

@huafu
Created July 18, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huafu/a63fef2bb7dbd3d59e129fd990159853 to your computer and use it in GitHub Desktop.
Save huafu/a63fef2bb7dbd3d59e129fd990159853 to your computer and use it in GitHub Desktop.
JavaScript real object clone
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