Hello, help me deal with the following:

The MDN indicates that the attributes writable , enumerable , configurable default is false ;

But why then:

 var person = {name}; console.log(Object.getOwnPropertyDescriptor(person,'name')); 19:20:38.695 VM130:2 {value: "", writable: true, enumerable: true, configurable: true} 

    1 answer 1

    If you create a property through defineProperty , it will get exactly the attributes that are specified by default:

     var person = {}; Object.defineProperty(person, 'name', {}); console.log(Object.getOwnPropertyDescriptor(person,'name')); > {value: undefined, writable: false, enumerable: false, configurable: false} 

    In ECMA 262 clause 11.1.5 there is a description of when in what cases which attributes are put; in particular:

     The production PropertyAssignment : PropertyName : AssignmentExpression is evaluated as follows: Let propName be the result of evaluating PropertyName. Let exprValue be the result of evaluating AssignmentExpression. Let propValue be GetValue(exprValue). Let desc be the Property Descriptor{ [[Value]]: propValue, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true } Return Property Identifier (propName, desc).