Last active
September 14, 2016 11:36
-
-
Save guzmanfg/dcb4c7ceab62aa8deeeb4602bc5a659d to your computer and use it in GitHub Desktop.
Clone function
This file contains 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
function clone(obj) { | |
var ctr = Object.getPrototypeOf(obj).constructor; | |
return Object.assign(new ctr(), obj); | |
} |
This file contains 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 function clone<T>(obj:T):T { | |
let ctr = Object.getPrototypeOf(obj).constructor; | |
return Object.assign(new ctr(), obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment