Здравствуйте, помогите разобраться со следующим:
На MDN указано,что атрибуты writable, enumerable, configurable по умолчанию false;
Но почему тогда:
var person = {name};
console.log(Object.getOwnPropertyDescriptor(person,'name'));
19:20:38.695 VM130:2 {value: "", writable: true, enumerable: true, configurable: true}
Если создавать свойство через defineProperty, оно получит именно те атрибуты, которые указаны по умолчанию:
var person = {};
Object.defineProperty(person, 'name', {});
console.log(Object.getOwnPropertyDescriptor(person,'name'));
> {value: undefined, writable: false, enumerable: false, configurable: false}
В стандарте ECMA 262 пункт 11.1.5 есть описание, когда в каких случаях какие атрибуты ставятся; в частности:
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).
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости