Skip to content

Instantly share code, notes, and snippets.

@ManzDev
Created March 15, 2016 00:12
Show Gist options
  • Save ManzDev/3515dedfa5c1b210f518 to your computer and use it in GitHub Desktop.
Save ManzDev/3515dedfa5c1b210f518 to your computer and use it in GitHub Desktop.
// JS (ES6)
obj = { uno: 1, dos: 2 }
var obj2 = Object.assign({}, obj);
obj.tres = 3
// JS (ES5)
obj = { uno: 1, dos: 2 }
var clone = function(original) {
var copy = Object.create({});
Object.getOwnPropertyNames(original).forEach(function(name) {
Object.defineProperty(copy, name, Object.getOwnPropertyDescriptor(original, name));
});
return copy;
};
obj2 = clone(obj)
obj.tres = 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment