Skip to content

Instantly share code, notes, and snippets.

@Himenon
Created October 23, 2019 12:41
Show Gist options
  • Save Himenon/3e210640d96557cd13cdb10b49ece2fe to your computer and use it in GitHub Desktop.
Save Himenon/3e210640d96557cd13cdb10b49ece2fe to your computer and use it in GitHub Desktop.
すでに生成されたインスタンスから、新しいインスタンスを生成するFunction
/**
* すでに生成されたインスタンスから、新しいインスタンスを生成する
* https://stackoverflow.com/questions/41474986/how-to-clone-a-javascript-es6-class-instance
* @param instance
*/
const cloneInstance = <T>(instance: T): T => Object.assign(Object.create(Object.getPrototypeOf(instance)), instance);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment