Created
March 15, 2016 00:12
-
-
Save ManzDev/3515dedfa5c1b210f518 to your computer and use it in GitHub Desktop.
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
// 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