Skip to content

Instantly share code, notes, and snippets.

@bhongy
Last active August 29, 2015 13:57
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 bhongy/9457566 to your computer and use it in GitHub Desktop.
Save bhongy/9457566 to your computer and use it in GitHub Desktop.
function copy(o) {
var copy = Object.create(Object.getPrototypeOf(o));
var propNames = Object.getOwnPropertyNames(o);
propNames.forEach(function(name) {
var desc = Object.getOwnPropertyDescriptor(o, name);
Object.defineProperty(copy, name, desc);
});
return copy;
}
/* Reference: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment