js 对象的属性特征

 

 

var user = {
    name:"angdh",
    age:11,

};

console.log(
    JSON.stringify(Object.getOwnPropertyDescriptors(user),null,2)
);

 

{
  "name": {
    "value": "angdh",
    "writable": true,
    "enumerable": true,
    "configurable": true
  },
  "age": {
    "value": 11,
    "writable": true,
    "enumerable": true,
    "configurable": true
  }
}

 


 

 

var user = {
    name:"angdh",
    age:11,

};

Object.defineProperty(user,"name",{

    value:"hhhh",
    writable:false
});


console.log(user.name); //hhhh

user.name = "fffff";

console.log(user.name); //hhhh



Object.defineProperty(user,"name",{

    value:"hhhh",
    writable:false,
  
       enumerable:false,   //不容许遍历
 
     configurable: false  //不容许删除 ,不容许重新配置
});
 
console.log(Object.keys(user)); // ["age"]
 

 

posted @ 2021-07-02 09:09  AngDH  阅读(56)  评论(0编辑  收藏  举报