-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.html
46 lines (45 loc) · 1.16 KB
/
object.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>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
// 使用 __proto__
var obj = {};
var descriptor = Object.create(null); // 没有继承的属性
// 默认没有enumerable,没有 configurable,没有 writable
descriptor.value = 'static';
Object.defineProperty(obj, 'key', descriptor);
console.log(obj);
// // 显式
// Object.defineProperty(obj, "key", {
// enumerable: false,
// configurable: false,
// writable: false,
// value: "static"
// });
//
// // 循环使用同一对象
// function withValue(value) {
// var d = withValue.d || (
// withValue.d = {
// enumerable: false,
// writable: false,
// configurable: false,
// value: null
// }
// );
// d.value = value;
// return d;
// }
// // ... 并且 ...
// Object.defineProperty(obj, "key", withValue("static"));
// console.log(obj);
// // 如果 freeze 可用, 防止代码添加或删除对象原型的属性
// // (value, get, set, enumerable, writable, configurable)
// (Object.freeze||Object)(Object.prototype);
</script>
</body>
</html>