Created
November 9, 2016 02:18
-
-
Save scq000/7a5dd66b6b89ef309c209665bd7989d2 to your computer and use it in GitHub Desktop.
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
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