value: 对象属性的默认值,默认值为undefined
configurable: 能否使用delete、能否需改属性特性、或能否修改访问器属性、,false为不可重新定义,默认值为true
enumerable: 对象属性是否可通过for-in循环,flase为不可循环,默认值为true
writable: 对象属性是否可修改,flase为不可修改,默认值为true
let person = {}; Object.defineProperty(person, ‘name‘, { value: ‘xixi‘, configurable: false, writable: false, enumerable: false, }); //value console.log(person.name); //xixi //writable person.name=‘biubiu‘; console.log(person.name); //xixi writable: false,不可修改value值 //configurable Object.defineProperty(person, ‘name‘, { value: ‘xixi‘, configurable: true, writable: true, enumerable: false, }); //configurable: false, 不可修改属性 报错 Uncaught TypeError delete person.name; //不可修改 //enumerable for(var i in person){ console.log(person[i]); } //enumerable: false,不可枚举 无结果 Object.defineProperty(person, ‘name2‘, { value: ‘hh‘, configurable: true, writable: true, enumerable: true, }); console.log(person.name2); //hh person.name2=‘jj‘; console.log(person.name2); //writable: true 可修改 jj Object.defineProperty(person, ‘name2‘, { value: ‘jj‘, configurable: true, writable: false, enumerable: true, }); //configurable: true,配置可修改 person.name2=‘jj2‘; console.log(person.name2); //jj writable改为false不可修改 for(var i in person){ console.log(person[i]); } //jj