Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 984235 of Reflect

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Reflect
  • Revision title: Reflect
  • Revision id: 984235
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment Remove {{harmony}}; remove "Experimental" tag; add link to ES draft spec

Revision Content

{{JSRef}}

Reflect is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of proxy handlers. Reflect is not a function object, so it's not constructible.

Description

Unlike most global objects, Reflect is not a constructor. You can not use it with a new operator or invoke the Reflect object as a function. All properties and methods of Reflect are static (just like the {{jsxref("Math")}} object).

Methods

The Reflect object provides the following static functions which have the same names as the proxy handler methods. Some of these methods are the same as corresponding methods on {{jsxref("Object")}}.

{{jsxref("Reflect.apply()")}}
Calls a target function with arguments as specified by the args parameter. See also {{jsxref("Function.prototype.apply()")}}.
{{jsxref("Reflect.construct()")}}
 The new operator as a function. Equivalent to calling new target(...args).
{{jsxref("Reflect.defineProperty()")}}
Similar to {{jsxref("Object.defineProperty()")}}. Returns a {{jsxref("Boolean")}}.
{{jsxref("Reflect.deleteProperty()")}}
The delete operator as a function. Equivalent to calling delete target[name].
{{jsxref("Reflect.enumerate()")}}
Like the for...in loop. Returns an iterator with the enumerable own and inherited properties of the target object.
{{jsxref("Reflect.get()")}}
A function that returns the value of properties.
{{jsxref("Reflect.getOwnPropertyDescriptor()")}}
Similar to {{jsxref("Object.getOwnPropertyDescriptor()")}}. Returns a property descriptor of the given property if it exists on the object,  {{jsxref("undefined")}} otherwise.
{{jsxref("Reflect.getPrototypeOf()")}}
Same as {{jsxref("Object.getPrototypeOf()")}}.
{{jsxref("Reflect.has()")}}
The in operator as function. Returns a boolean indicating whether an own or inherited property exists.
{{jsxref("Reflect.isExtensible()")}}
Same as {{jsxref("Object.isExtensible()")}}.
{{jsxref("Reflect.ownKeys()")}}
Returns an array of the target object's own (not inherited) property keys.
{{jsxref("Reflect.preventExtensions()")}}
Similar to {{jsxref("Object.preventExtensions()")}}. Returns a {{jsxref("Boolean")}}.
{{jsxref("Reflect.set()")}}
A function that assigns values to properties. Returns a {{jsxref("Boolean")}} that is true if the update was successful.
{{jsxref("Reflect.setPrototypeOf()")}}
A function that sets the prototype of an object.

Specifications

Specification Status Comment
{{SpecName('ES6', '#sec-reflect-object', 'Reflect')}} {{Spec2('ES6')}} Initial definition.
{{SpecName('ESDraft', '#sec-reflect-object', 'Reflect')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatNo}} {{CompatVersionUnknown}} {{CompatGeckoDesktop("42")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatNo}} {{CompatGeckoMobile("42")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

  • The {{jsxref("Proxy")}} global object.
  • The {{jsxref("Proxy.handler", "handler")}} object.

Revision Source

<div>{{JSRef}}</div>

<p><strong>Reflect</strong> is a built-in object that provides methods for interceptable JavaScript operations. The methods are the same as those of <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler">proxy handlers</a>. <code>Reflect</code> is not a function object, so it's not constructible.</p>

<h2 id="Description">Description</h2>

<p>Unlike most&nbsp;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="Methods">Methods</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>&nbsp;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.enumerate()")}}</dt>
 <dd>Like the <a href="/en-US/docs/Web/JavaScript/Reference/Statements/for...in"><code>for...in</code></a> loop. Returns an iterator with the enumerable own and inherited properties of the target object.</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,&nbsp; {{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="Specifications">Specifications</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-object', 'Reflect')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-reflect-object', 'Reflect')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("42")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("42")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>The {{jsxref("Proxy")}} global object.</li>
 <li>The {{jsxref("Proxy.handler", "handler")}} object.</li>
</ul>
Revert to this revision