?JavaScrpt高級(jí)程序設(shè)計(jì)第三版中,說(shuō)對(duì)象屬性的configurable特性為false時(shí)音念,Object.defineProperty不可再修改除writable之外的特性爵赵,經(jīng)過(guò)試驗(yàn),實(shí)際情況并非如此,此時(shí)壹甥,若writable原來(lái)為true,仍然可以改為false壶熏;但是如果writable原為false句柠,則不可再修改為true
var person={name:'實(shí)際名字',age:'24'};
Object.defineProperty(person,'name',{
configurable:false,
writable:true,
});
person.name='虛假名字1';
console.log(person.name) //虛假名字1
Object.defineProperty(person,'name',{
writable:false,
});
person.name='虛假名字2';
console.log(person.name) //虛假名字1
?以上configurable為false時(shí),writable由true修改為false成功
var person={name:'實(shí)際名字',age:'24'};
Object.defineProperty(person,'name',{
configurable:false,
writable:false,
});
person.name='虛假名字1'; //實(shí)際名字
console.log(person.name)
Object.defineProperty(person,'name',{
writable:true,
});
person.name='虛假名字2';
console.log(person.name) //TypeError: Cannot redefine property: name
?以上棒假,configurable為flase時(shí)溯职,writable由false修改為true報(bào)錯(cuò)