Skip to content

Instantly share code, notes, and snippets.

@scq000
Created November 9, 2016 02:18
Show Gist options
  • Save scq000/7a5dd66b6b89ef309c209665bd7989d2 to your computer and use it in GitHub Desktop.
Save scq000/7a5dd66b6b89ef309c209665bd7989d2 to your computer and use it in GitHub Desktop.
function Product(name, price) {
this.name = name;
this.price = price;
}
// Object.defineProperty(Product.prototype, "discount", {
// get() {
// return 1;
// },
// set(value) {
// this.discount = value;
// }
// });
Object.defineProperty(Product.prototype, "discount", {
value: 1,
configurable: true, //是否可以被删除
enumberable: true, //能否通过for..in取到
});
var shoes = new Product("Shoes", 20);
var tshirt = new Product("T-shirt", 30);
console.log(shoes.discount);
console.log(tshirt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment