-
-
Save DavidBruant/7892647 to your computer and use it in GitHub Desktop.
clone for @JeremiePat
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 obj = { | |
a: 1, | |
get b(){ return 2 }, | |
c: 3 | |
} | |
Object.defineProperty(obj, 'c', {configurable: false, writable: false}); | |
function clone(o){ | |
var c = Object.create(Object.getPrototypeOf(o)); | |
Object.getOwnPropertyNames(o).forEach(function(p){ | |
Object.defineProperty(c, p, Object.getOwnPropertyDescriptor(o, p)); | |
}) | |
return c; | |
} | |
console.log(clone(obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment