<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!--
1.Object_defineProperty()的使用
Object.defineProperty(对象名称,属性名称,添加的属性)
增删改查Object里的属性
enumerable:false //控制属性是否可以枚举(枚举:数组,便利读取不到里面属性)如: console.log(Object.keys(person));
writable:false //控制属性是否可以被修改(没啥用)
configurable:false //控制属性是否可以删除
set():
get():
-->
</head>
<body>
<script>
let number = 20;
let person = {
name : "张三",
sex : '男',
}
Object.defineProperty(person,'age',{
value1: 19,
//可枚举
enumerable:true,
//删除
configurable:true,
get:function re() {
console.log('读取get了');
return number;
},
set(value1) {
console.log('修改了number属性',value1);
number = value1;
}
})
//console.log(person);
//console.log(Object.keys(person));
</script>
</body>
</html>