Skip to content

Instantly share code, notes, and snippets.

@LasaleFamine
Created April 4, 2018 12:29
Show Gist options
  • Select an option

  • Save LasaleFamine/89ed13e8112c8a50a3e53ffb8f2281f0 to your computer and use it in GitHub Desktop.

Select an option

Save LasaleFamine/89ed13e8112c8a50a3e53ffb8f2281f0 to your computer and use it in GitHub Desktop.
Copy object -> definitive way ES2017
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