blob: 7feb69f921fb7c5c4e897aaf278fe0a02c8783f8 (
plain)
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
|
---
title: Reflect
slug: Web/JavaScript/Reference/Global_Objects/Reflect
translation_of: Web/JavaScript/Reference/Global_Objects/Reflect
---
<div>{{JSRef}}</div>
<p><strong>Reflect</strong> 是一個內建物件,提供了用於獲取可截取之 JavaScript 操作的方法。這些方法與 <a href="/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler">proxy handlers</a> 的方法相同。<code>Reflect</code> 不是一個函式物件,因此它是不可建構的。</p>
<h2 id="描述">描述</h2>
<p>Unlike most global objects, <code>Reflect</code> is not a constructor. You can not use it with a <a href="/en-US/docs/Web/JavaScript/Reference/Operators/new"><code>new</code> operator</a> or invoke the <code>Reflect</code> object as a function. All properties and methods of <code>Reflect</code> are static (just like the {{jsxref("Math")}} object).</p>
<h2 id="方法">方法</h2>
<p>The <code>Reflect</code> object provides the following static functions which have the same names as the <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler">proxy handler methods</a>. Some of these methods are the same as corresponding methods on {{jsxref("Object")}}.</p>
<dl>
<dt>{{jsxref("Reflect.apply()")}}</dt>
<dd>Calls a target function with arguments as specified by the <code>args</code> parameter. See also {{jsxref("Function.prototype.apply()")}}.</dd>
<dt>{{jsxref("Reflect.construct()")}}</dt>
<dd> The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/new"><code>new</code> operator</a> as a function. Equivalent to calling <code>new target(...args)</code>.</dd>
<dt>{{jsxref("Reflect.defineProperty()")}}</dt>
<dd>Similar to {{jsxref("Object.defineProperty()")}}. Returns a {{jsxref("Boolean")}}.</dd>
<dt>{{jsxref("Reflect.deleteProperty()")}}</dt>
<dd>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/delete"><code>delete</code> operator</a> as a function. Equivalent to calling <code>delete target[name]</code>.</dd>
<dt>{{jsxref("Reflect.get()")}}</dt>
<dd>A function that returns the value of properties.</dd>
<dt>{{jsxref("Reflect.getOwnPropertyDescriptor()")}}</dt>
<dd>Similar to {{jsxref("Object.getOwnPropertyDescriptor()")}}. Returns a property descriptor of the given property if it exists on the object, {{jsxref("undefined")}} otherwise.</dd>
<dt>{{jsxref("Reflect.getPrototypeOf()")}}</dt>
<dd>Same as {{jsxref("Object.getPrototypeOf()")}}.</dd>
<dt>{{jsxref("Reflect.has()")}}</dt>
<dd>The <a href="/en-US/docs/Web/JavaScript/Reference/Operators/in"><code>in</code> operator</a> as function. Returns a boolean indicating whether an own or inherited property exists.</dd>
<dt>{{jsxref("Reflect.isExtensible()")}}</dt>
<dd>Same as {{jsxref("Object.isExtensible()")}}.</dd>
<dt>{{jsxref("Reflect.ownKeys()")}}</dt>
<dd>Returns an array of the target object's own (not inherited) property keys.</dd>
<dt>{{jsxref("Reflect.preventExtensions()")}}</dt>
<dd>Similar to {{jsxref("Object.preventExtensions()")}}. Returns a {{jsxref("Boolean")}}.</dd>
<dt>{{jsxref("Reflect.set()")}}</dt>
<dd>A function that assigns values to properties. Returns a {{jsxref("Boolean")}} that is <code>true</code> if the update was successful.</dd>
<dt>{{jsxref("Reflect.setPrototypeOf()")}}</dt>
<dd>A function that sets the prototype of an object.</dd>
</dl>
<h2 id="規範">規範</h2>
{{Specifications}}
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
{{Compat}}
<h2 id="參見">參見</h2>
<ul>
<li>The {{jsxref("Proxy")}} global object.</li>
<li>The {{jsxref("Proxy.handler", "handler")}} object.</li>
</ul>
|