4
我正在阅读ECMAScript 5(在浏览器中,使用ES5-shim,我知道它不支持所有内容)。而只是为了消除混淆,考虑到我有这个对象(从this post被盗):ECMAScript 5中属性描述符和属性赋值的区别?
var Person = {
firstName: null, // the person’s first name
lastName: null // the person’s last name
};
是否有此之间的任何差别:
var Employee = Object.create(Person, {
id: {
value: null,
enumerable: true,
configurable: true,
writable: true
}
});
这:
var Employee = Object.create(Person);
Employee.id = null;
// Or using jQuery.extend
$.extend(Employee, {
id : null
});
据我了解enumerable,可配置和可写的设置为真时,这样定义一个属性(这也将向后兼容传统的JavaScript引擎)。我是否错过了某些东西,或者只要我希望这是所需的行为,就可以忽略详细的属性描述符?
谢谢,只是想确认一下。我还注意到,使用属性描述符时的默认值不同。我仍然有点小心使用它,因为无论如何shim默认回到遗留系统。 – Daff