SOURCE

console 命令行工具 X clear

                    
>
console
var book = {
  _year: 2004,
  edition: 1
};
Object.defineProperty(book, "year", {
  set: function(newValue) {
    if (newValue > 2004) {
      this._year = newValue;
      this.edition += newValue - 2004;
    }
  }
});
book.year = 2005;
alert(book.edition); //2