Created
January 23, 2012 12:08
-
-
Save ollym/1662767 to your computer and use it in GitHub Desktop.
ECMA5 Object Cloning
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
Object.clone = function(obj) { | |
return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyNames(obj).reduce(function(memo, name) { | |
return (memo[name] = Object.getOwnPropertyDescriptor(obj, name)) && memo; | |
}, {})); | |
} |
that's a shallow clone and not a deep one tho, right?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And in ES6