// var person = {};
// Object.defineProperty(person, "name", {
// writable: false,
// configurable: false,
// value: "wzn"
// });
// console.log(person.name);
// person.name = "123";
// console.log(person.name);
// delete person.name;
// console.log(person.name);
// var book = {
// _year: 2004,
// edition: 1
// };
// Object.defineProperty(book, "year", {
// get: function(){
// return this._year;
// },
// set: function(newYear){
// if (newYear > 2004){
// this._year = newYear;
// this.edition += newYear - 2004;
// }
// }
// });
// book.year = 2005;
// console.log(book.edition);
var book2 = {};
Object.defineProperties(book2, {
_year: {
writable: true,
value: 2004
},
edition: {
writable: true,
value: 2
},
year: {
get: function(){
return this._year;
},
set: function(newValue){
if (newValue > 2004){
this._year = newValue;
this.edition += newValue - 2004;
}
}
}
});
var descriptor = Object.getOwnPropertyDescriptor(book2, "_year");
console.log(descriptor.value);
console.log(descriptor.configurable);
console.log(descriptor.writable);
console.log(typeof descriptor.get);
var descriptor = Object.getOwnPropertyDescriptor(book2, "year");
console.log(descriptor.configurable);
console.log(descriptor.enumerable);
console.log(typeof descriptor.get);