-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
93 lines (63 loc) · 1.74 KB
/
index.md
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: handler.isExtensible()
slug: Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/isExtensible
---
{{JSRef}}
**handler.isExtensible()** 方法用于拦截对对象的 Object.isExtensible()。
{{EmbedInteractiveExample("pages/js/proxyhandler-isextensible.html", "taller")}}
## 语法
```js
var p = new Proxy(target, {
isExtensible: function (target) {},
});
```
### 参数
下列参数将会被传递给 `isExtensible`方法。this 绑定在 handler 对象上。
- `target`
- : 目标对象。
### 返回值
`isExtensible`方法必须返回一个 Boolean 值或可转换成 Boolean 的值。
## 描述
handler.isExtensible() 用于拦截对对象的 Object.isExtensible()。
### 拦截
该方法会拦截目标对象的以下操作:
- {{jsxref("Object.isExtensible()")}}
- {{jsxref("Reflect.isExtensible()")}}
### 约束
如果违背了以下的约束,proxy 会抛出 TypeError:
- `Object.isExtensible(proxy)` 必须同 `Object.isExtensible(target)` 返回相同值。
## 示例
以下代码演示{{jsxref("Object.isExtensible()")}}.
```js
var p = new Proxy(
{},
{
isExtensible: function (target) {
console.log("called");
return true; // 也可以 return 1; 等表示为 true 的值
},
},
);
console.log(Object.isExtensible(p)); // "called"; outputs true
```
以下代码演示违反约束的情况。
```js
var p = new Proxy(
{},
{
isExtensible: function (target) {
return false; // return 0; return NaN 等都会报错
},
},
);
Object.isExtensible(p); // TypeError is thrown
```
## 规范
{{Specifications}}
## 浏览器兼容性
{{Compat}}
## 参见
- {{jsxref("Proxy")}}
- {{jsxref("Proxy.handler", "handler")}}
- {{jsxref("Object.isExtensible()")}}
- {{jsxref("Reflect.isExtensible()")}}