var a={};
Object.defineProperty(a,"z",{value:10});
var obj=new Object(a);
Object.defineProperty(obj,"z",{value:100});//报Uncaught TypeError: Cannot redefine property: z
Object.getOwnPropertyDescriptor(obj,"z");//configurable: false enumerable: false value: 10 writable: false
var a={z:1};
Object.defineProperty(a,"z",{value:10});
var obj=new Object(a);
Object.defineProperty(obj,"z",{value:100});
Object.getOwnPropertyDescriptor(obj,"z");//configurable: true enumerable: true value: 100 writable: true
为什么第一种写法会报Uncaught TypeError: Cannot redefine property: z这个故障,是因为第一种情况下z属性的几个标签都为false的原因吗?如果是,为什么为false就不能重新设呢?
橋本奈奈未
相关分类