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.
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.
Unlike most global objects, Reflect
is not a constructor. You cannot 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 Math
object).
The Reflect
object provides the following static functions which have the same names as the proxy handler methods.
Some of these methods are also the same as corresponding methods on Object
, although they do have some subtle differences between them.
Reflect.apply()
Calls a target
function with arguments as specified by the argumentsList
parameter. See also Function.prototype.apply()
.
Reflect.construct()
The new
operator as a function. Equivalent to calling new target(...argumentsList)
. Also provides the option to specify a different prototype.
Reflect.defineProperty()
Similar to Object.defineProperty()
. Returns a boolean that is true
if the property was successfully defined.
Reflect.deleteProperty()
The delete
operator as a function. Equivalent to calling delete target[propertyKey]
.
Reflect.get()
Returns the value of the property. Works like getting a property from an object (target[propertyKey]
) as a function.
Reflect.getOwnPropertyDescriptor()
Similar to Object.getOwnPropertyDescriptor()
. Returns a property descriptor of the given property if it exists on the object, undefined
otherwise.
Reflect.getPrototypeOf()
Same as Object.getPrototypeOf()
.
Reflect.has()
Returns a boolean indicating whether the target has the property. Either as own or inherited. Works like the in
operator as a function.
Reflect.isExtensible()
Same as Object.isExtensible()
. Returns a boolean that is true
if the target is extensible.
Reflect.ownKeys()
Returns an array of the target object's own (not inherited) property keys.
Reflect.preventExtensions()
Similar to Object.preventExtensions()
. Returns a boolean that is true
if the update was successful.
Reflect.set()
A function that assigns values to properties. Returns a boolean that is true
if the update was successful.
Reflect.setPrototypeOf()
A function that sets the prototype of an object. Returns a boolean that is true
if the update was successful.
const duck = { name: 'Maurice', color: 'white', greeting() { console.log(`Quaaaack! My name is ${this.name}`); } } Reflect.has(duck, 'color'); // true Reflect.has(duck, 'haircut'); // false
Reflect.ownKeys(duck); // [ "name", "color", "greeting" ]
Reflect.set(duck, 'eyes', 'black'); // returns "true" if successful // "duck" now contains the property "eyes: 'black'"
Specification |
---|
ECMAScript Language Specification # sec-reflect-object |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | Deno | Node.js | |
Reflect |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
apply |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
construct |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
defineProperty |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
deleteProperty |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
get |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
getOwnPropertyDescriptor |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
getPrototypeOf |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
has |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
isExtensible |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
ownKeys |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
preventExtensions |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
set |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
setPrototypeOf |
49 |
12 |
42 |
No |
36 |
10 |
49 |
49 |
42 |
36 |
10 |
5.0 |
1.0 |
6.0.0 |
Proxy
global objectProxy()
constructor
© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect