SOURCE

var book = {};
Object.defineProperties(book, {
    //_year和edition是数据属性,有以下四个内部属性
    _year: {
        value: 2004,
        //在defineProperties函数中,这三个属性没有明确写出的话,默认情况下都是false
        //而在其他情况中则都是true,比如正常地创建属性时
        writable: true,//若不明确写出来,下面的alert(book.year)永远都输出2004
                       //因为其值在writable为false时无法改变其值
        configurable: true,
        enumerable: true
    },

    edition: {
        value: 1,
        writable: true,
        configurable: true,
        enumerable: true
    },

    //year是访问器属性,有以下四个内部属性
    year: {
        get: function () {
            return this._year;
        },
        set: function (newValue) {
            if (newValue > 2004) {
                this._year = newValue;
                this.edition += newValue - 2004;
            }
        },
        enumerable: true,
        configurable: true
    }
});

book.edition = 2005;
alert(book.edition);

//检验不写enumerable时,默认是true还是false,答案是false
for (var i in book) {
    alert(i);
}
console 命令行工具 X clear

                    
>
console