aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.html93
1 files changed, 93 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.html b/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.html
new file mode 100644
index 0000000000..7d24c17fe6
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/reflect/preventextensions/index.html
@@ -0,0 +1,93 @@
+---
+title: Reflect.preventExtensions()
+slug: Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions
+translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions
+---
+<div>{{JSRef}}</div>
+
+<p>静态方法 <code><strong>Reflect</strong></code><strong><code>.preventExtensions()</code></strong> 方法阻止新属性添加到对象 (例如:防止将来对对象的扩展被添加到对象中)。该方法与 {{jsxref("Object.preventExtensions()")}}相似,但有一些不同点。详情可见 {{anch("与_Object.preventExtensions_的不同点", "differences")}}。</p>
+
+<p>{{EmbedInteractiveExample("pages/js/reflect-preventextensions.html")}}</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">Reflect.preventExtensions(target)
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>target</code></dt>
+ <dd>阻止扩展的目标对象。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>返回一个 {{jsxref("Boolean")}} 值表明目标对象是否成功被设置为不可扩展。</p>
+
+<h3 id="异常">异常</h3>
+
+<p>抛出一个 {{jsxref("TypeError")}} 错误,如果 <code>target</code> 不是 {{jsxref("Object")}}。</p>
+
+<h2 id="描述">描述</h2>
+
+<p><code>Reflect.preventExtensions</code> 方法阻止新属性添加到对象 (例如:防止将来对对象的扩展被添加到对象中)。该方法与  {{jsxref("Object.preventExtensions()")}} 方法相似。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="使用_Reflect.preventExtensions">使用 <code>Reflect.preventExtensions()</code></h3>
+
+<p>详情可见 {{jsxref("Object.preventExtensions()")}}.</p>
+
+<pre class="brush: js">// Objects are extensible by default.
+var empty = {};
+Reflect.isExtensible(empty); // === true
+
+// ...but that can be changed.
+Reflect.preventExtensions(empty);
+Reflect.isExtensible(empty); // === false
+</pre>
+
+<h3 id="与_Object.preventExtensions_的不同点">与 <code>Object.preventExtensions()</code> 的不同点</h3>
+
+<p>如果该方法的 <em><code>target</code></em> 参数不是一个对象(是原始值),那么将造成一个 {{jsxref("TypeError")}} 异常。 对于{{jsxref("Object.preventExtensions()")}} 方法, 非对象的 <em><code>target</code></em> 参数将被强制转换为对象。</p>
+
+<pre class="brush: js">Reflect.preventExtensions(1);
+// TypeError: 1 is not an object
+
+Object.preventExtensions(1);
+// 1
+</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('ES6', '#sec-reflect.preventextensions', 'Reflect.preventExtensions')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-reflect.preventextensions', 'Reflect.preventExtensions')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("javascript.builtins.Reflect.preventExtensions")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{jsxref("Reflect")}}</li>
+ <li>{{jsxref("Object.isExtensible()")}}</li>
+</ul>