Provides methods for use in operations that are intercepted.
Syntax
Reflect.[method]
Parameters
method
Required. Name of one of the methods of the Reflect object.
Remarks
The Reflect object cannot be instantiated with the new operator.
Reflect methods are often used with proxies because they allow you to delegate to default behavior without implementing the default behavior in your code.
Reflect provides a static method with the same name as each proxy trap. The descriptions in the table are not exhaustive.
| Method | Description |
|---|---|
Reflect.apply(target, thisArg, args) |
Similar to the apply method of the Function object. |
Reflect.construct(target, args) |
A function equivalent for the new operator. |
Reflect.defineProperty(target, propertyName, descriptor) |
Similar to Object.defineProperty. Returns a boolean value indicating whether the call succeeded. |
Reflect.deleteProperty(target, propertyName) |
Similar to the delete statement. Returns a boolean value indicating whether the call succeeded. |
Reflect.enumerate(target) |
Similar to for...in statement, Object.getOwnPropertySymbols, Object.keys function, and JSON.stringify. |
Reflect.get(target, propertyName, receiver) |
A function equivalent for any getter properties. |
Reflect.getOwnPropertyDescriptor(target, propertyName) |
Similar to Object.getOwnPropertyDescriptor. Returns a Boolean value indicating whether the call succeeded. |
Reflect.getPrototypeOf(target) |
Similar to Object.getPrototypeOf. |
Reflect.has(target, propertyName) |
Similar to the in operator, hasOwnProperty Method (Object), and other methods. Returns a Boolean value indicating whether the call succeeded. |
Reflect.isExtensible(target) |
Similar to Object.isExtensible. |
Reflect.ownKeys(target) |
Similar to Object.getOwnPropertyNames. |
Reflect.preventExtensions(target) |
Similar to Object.preventExtensions. Returns a boolean value indicating whether the call succeeded. |
Reflect.set(target, propertyName, value, receiver) |
Similar to using any setter property. Returns a Boolean value indicating whether the call succeeded. |
Reflect.setPrototypeOf(target, prototype) |
Similar to Object.setPrototypeOf. Returns a boolean value indicating whether the call succeeded. |
Example
The following code example shows how use Reflect.get to write a proxy that blocks get operations for properties that begin with an underscore.
var p = new Proxy({}, {
get(k, t, r) {
// return undefined if key begins with underscore
if(k[0] === '_') return undefined;
// otherwise do default behavior
return Reflect.get(k, t, r);
}
});
p._foo = 1;
console.log(p._foo);
p.foo = 1;
console.log(p.foo);
// Output:
// undefined
// 1
Requirements
Supported in Microsoft Edge (Edge browser). Also supported in Store apps (Microsoft Edge on Windows 10). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.


