Skip to content

Instantly share code, notes, and snippets.

@wibblymat
Last active December 10, 2015 21:59
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 wibblymat/4498805 to your computer and use it in GitHub Desktop.
Save wibblymat/4498805 to your computer and use it in GitHub Desktop.
ES5 object clone
var clone = function(original)
{
var copy = Object.create({});
Object.getOwnPropertyNames(original).forEach(function(name)
{
Object.defineProperty(copy, name, Object.getOwnPropertyDescriptor(original, name));
});
return copy;
};
@wibblymat
Copy link
Author

This little function clones an object. Seems to be an elegant solution, but what am I missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment