Last active
December 10, 2015 21:59
-
-
Save wibblymat/4498805 to your computer and use it in GitHub Desktop.
ES5 object clone
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
var clone = function(original) | |
{ | |
var copy = Object.create({}); | |
Object.getOwnPropertyNames(original).forEach(function(name) | |
{ | |
Object.defineProperty(copy, name, Object.getOwnPropertyDescriptor(original, name)); | |
}); | |
return copy; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This little function clones an object. Seems to be an elegant solution, but what am I missing?