Created
April 4, 2018 12:29
-
-
Save LasaleFamine/89ed13e8112c8a50a3e53ffb8f2281f0 to your computer and use it in GitHub Desktop.
Copy object -> definitive way ES2017
This file contains hidden or 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
| const Product = { | |
| name: 'Some name', | |
| price: 10, | |
| set discount(x) { | |
| this.disc = x; | |
| }, | |
| get discount() { | |
| return this.disc; | |
| } | |
| }; | |
| const newProductCopied = Object.defineProperties({}, Object.getOwnPropertyDescriptors(Product)); | |
| /*** | |
| > {name: "Some name", price: 10} | |
| discount: (...) | |
| name: "Some name" | |
| price: 10 | |
| get discount: ƒ discount() | |
| set discount: ƒ discount(x) | |
| ***/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment