大家好,我在读书时发现如下问题,该问题出现在如下书中的第6.1.3章节,但只看以下描述一样可以解答,非常谢谢帮助!
《Professional JavaScript for Web Developers_Third Edition》(JavaScript 高级程序设计(第3版))问题在于Object.getOwnPropertyDescriptor()。书中说任何一个对象的属性的attribute,在未设置enumerable和configurable时都应该默认为true,但在如下代码结尾alert时结果都是false。这是为什么呢?        var book = {};
        
        Object.defineProperties(book, {
            _year: {
                value: 2004
            },
            
            edition: {
                value: 1
            },
            
            year: {            
                get: function(){
                    return this._year;
                },
                
                set: function(newValue){
                    if (newValue > 2004) {
                        this._year = newValue;
                        this.edition += newValue - 2004;
                    }                  
                }            
            }        
        });
           
        var descriptor = Object.getOwnPropertyDescriptor(book, "_year");
        alert(descriptor.value);          //2004
        alert(descriptor.configurable);   //false
        alert(typeof descriptor.get);     //"undefined"
        
        var descriptor = Object.getOwnPropertyDescriptor(book, "year");
        alert(descriptor.value);          //undefined
        alert(descriptor.enumerable);     //false
        alert(typeof descriptor.get);     //"function"Property Attributesjavascriptenumerableconfigurable