aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible/index.html123
1 files changed, 123 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible/index.html b/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible/index.html
new file mode 100644
index 0000000000..7be418197f
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/isextensible/index.html
@@ -0,0 +1,123 @@
+---
+title: handler.isExtensible()
+slug: Web/JavaScript/Reference/Global_Objects/Proxy/handler/isExtensible
+tags:
+ - ECMAScript 2015
+ - JavaScript
+ - Method
+ - Proxy
+translation_of: Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/isExtensible
+---
+<div>{{JSRef}}<br>
+<strong>handler.isExtensible() </strong>方法用于拦截对对象的Object.isExtensible()。</div>
+
+<div>
+<p>{{EmbedInteractiveExample("pages/js/proxyhandler-isextensible.html", "taller")}}</p>
+</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">var p = new Proxy(target, {
+ isExtensible: function(target) {
+ }
+});
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<p>下列参数将会被传递给 <code>isExtensible</code>方法。 this 绑定在 handler 对象上。</p>
+
+<dl>
+ <dt><code>target</code></dt>
+ <dd>目标对象。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p><code>isExtensible</code>方法必须返回一个 Boolean值或可转换成Boolean的值。</p>
+
+<h2 id="描述">描述</h2>
+
+<p>handler.isExtensible()用于拦截对对象的Object.isExtensible()。</p>
+
+<h3 id="拦截">拦截</h3>
+
+<p>该方法会拦截目标对象的以下操作:</p>
+
+<ul>
+ <li>{{jsxref("Object.isExtensible()")}}</li>
+ <li>{{jsxref("Reflect.isExtensible()")}}</li>
+</ul>
+
+<h3 id="约束">约束</h3>
+
+<p>如果违背了以下的约束,proxy会抛出 TypeError:</p>
+
+<ul>
+ <li><code>Object.isExtensible(proxy)</code> 必须同<code>Object.isExtensible(target)</code>返回相同值。也就是必须返回true或者为true的值,返回false和为false的值都会报错。</li>
+</ul>
+
+<h2 id="示例">示例</h2>
+
+<p>以下代码演示{{jsxref("Object.isExtensible()")}}.</p>
+
+<pre class="brush: js">var p = new Proxy({}, {
+ isExtensible: function(target) {
+ console.log('called');
+ return true;//也可以return 1;等表示为true的值
+ }
+});
+
+console.log(Object.isExtensible(p)); // "called"
+ // true
+</pre>
+
+<p>以下代码演示违反约束的情况。</p>
+
+<pre class="brush: js">var p = new Proxy({}, {
+ isExtensible: function(target) {
+ return false;//return 0;return NaN等都会报错
+ }
+});
+
+Object.isExtensible(p); // TypeError is thrown
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-proxy-object-internal-methods-and-internal-slots-isextensible', '[[IsExtensible]]')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-proxy-object-internal-methods-and-internal-slots-isextensible', '[[IsExtensible]]')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("javascript.builtins.Proxy.handler.isExtensible")}}</p>
+</div>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>{{jsxref("Proxy")}}</li>
+ <li>{{jsxref("Proxy.handler", "handler")}}</li>
+ <li>{{jsxref("Object.isExtensible()")}}</li>
+ <li>{{jsxref("Reflect.isExtensible()")}}</li>
+</ul>