aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 12:56:40 +0100
commit310fd066e91f454b990372ffa30e803cc8120975 (patch)
treed5d900deb656a5da18e0b60d00f0db73f3a2e88e /files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.gz
translated-content-310fd066e91f454b990372ffa30e803cc8120975.tar.bz2
translated-content-310fd066e91f454b990372ffa30e803cc8120975.zip
unslug zh-cn: move
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct/index.html130
1 files changed, 0 insertions, 130 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct/index.html b/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct/index.html
deleted file mode 100644
index 209e9752e3..0000000000
--- a/files/zh-cn/web/javascript/reference/global_objects/proxy/handler/construct/index.html
+++ /dev/null
@@ -1,130 +0,0 @@
----
-title: handler.construct()
-slug: Web/JavaScript/Reference/Global_Objects/Proxy/handler/construct
-translation_of: Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/construct
----
-<div>{{JSRef}}</div>
-
-<p><code><strong>handler.construct()</strong></code> 方法用于拦截{{jsxref("Operators/new", "new")}} 操作符. 为了使new操作符在生成的Proxy对象上生效,用于初始化代理的目标对象自身必须具有[[Construct]]内部方法(即 <code>new target</code> 必须是有效的)。</p>
-
-<p>{{EmbedInteractiveExample("pages/js/proxyhandler-construct.html", "taller")}}</p>
-
-<h2 id="语法">语法</h2>
-
-<pre class="brush: js">var p = new Proxy(target, {
- construct: function(target, argumentsList, newTarget) {
- }
-});
-</pre>
-
-<h3 id="参数">参数</h3>
-
-<p>下面的参数将会传递给<code>construct</code>方法,<code>this</code>绑定在handler上。</p>
-
-<dl>
- <dt><code>target</code></dt>
- <dd>目标对象。</dd>
- <dt><code>argumentsList</code></dt>
- <dd>constructor的参数列表。</dd>
- <dt><code>newTarget</code></dt>
- <dd>最初被调用的构造函数,就上面的例子而言是p。</dd>
-</dl>
-
-<h3 id="返回值">返回值</h3>
-
-<p><code>construct</code> 方法必须返回一个对象。</p>
-
-<h2 id="描述">描述</h2>
-
-<p><code><strong>handler.construct()</strong></code> 方法用于拦截 {{jsxref("Operators/new", "new")}}操作符。</p>
-
-<h3 id="拦截">拦截</h3>
-
-<p>该拦截器可以拦截以下操作:</p>
-
-<ul>
- <li><code>new proxy(...args)</code></li>
- <li>{{jsxref("Reflect.construct()")}}</li>
-</ul>
-
-<h3 id="约束">约束</h3>
-
-<p>如果违反以下约定,代理将会抛出错误 {{jsxref("TypeError")}}:</p>
-
-<ul>
- <li>必须返回一个对象.</li>
-</ul>
-
-<h2 id="示例">示例</h2>
-
-<p>下面代码演示如何拦截 {{jsxref("Operators/new", "new")}} 操作。</p>
-
-<pre class="brush: js">var p = new Proxy(function() {}, {
- construct: function(target, argumentsList, newTarget) {
- console.log('called: ' + argumentsList.join(', '));
- return { value: argumentsList[0] * 10 };
- }
-});
-
-console.log(new p(1).value); // "called: 1"
- // 10
-</pre>
-
-<p>下面的代码违反了约定.</p>
-
-<pre class="brush: js">var p = new Proxy(function() {}, {
- construct: function(target, argumentsList, newTarget) {
- return 1;
- }
-});
-
-new p(); // TypeError is thrown
-</pre>
-
-<p>下面的代码未能正确的初始化Proxy。Proxy初始化时,传给它的<code>target</code> 必须具有一个有效的constructor供<code>new</code>操作符调用。</p>
-
-<pre class="brush: js">var p = new Proxy({}, {
-  construct: function(target, argumentsList, newTarget) {
-  return {};
-  }
-});
-
-new p(); // TypeError is thrown, "p" is not a constructor
-</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-construct-argumentslist-newtarget', '[[Construct]]')}}</td>
- <td>{{Spec2('ES2015')}}</td>
- <td>Initial definition.</td>
- </tr>
- <tr>
- <td>{{SpecName('ESDraft', '#sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget', '[[Construct]]')}}</td>
- <td>{{Spec2('ESDraft')}}</td>
- <td> </td>
- </tr>
- </tbody>
-</table>
-
-<h2 id="浏览器兼容性">浏览器兼容性</h2>
-
-<div>{{Compat("javascript.builtins.Proxy.handler.construct")}}</div>
-
-<div id="compat-mobile"> </div>
-
-<h2 id="相关主题">相关主题</h2>
-
-<ul>
- <li>{{jsxref("Proxy")}}</li>
- <li>{{jsxref("Proxy.handler", "handler")}}</li>
- <li>{{jsxref("Operators/new", "new")}} operator.</li>
- <li>{{jsxref("Reflect.construct()")}}</li>
-</ul>