-
Notifications
You must be signed in to change notification settings - Fork 0
/
object1.html
46 lines (44 loc) · 1.16 KB
/
object1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<script>
/* var obj = {
name: "张三"
};
Object.defineProperty(obj, "age", {
//数据描述符
value: 20, //值
enumerable: false, //是否可枚举
writable: false, //是否可以修改值
configurable: false //是否可以修改属性
});
for (var attr in obj) {
console.log(attr);
}
delete obj.age;
console.log(obj); */
// 存取描述符
/* var obj = { name: "张三" };
var age = 20;
Object.defineProperty(obj, "age", {
get: function() {
console.log("你获取了数据");
return age;
},
set: function(e) {
age = e;
},
configurable: true,
enumerable: true
});
obj.age = 30;
console.log(obj.age); */
</script>
</body>
</html>