JavaScript: Reflect
New in JS2015.
Reflect
is the value of the property key "Reflect"
of the Global Object
.
console.log(globalThis["Reflect"] === Reflect);
Type
console.log(typeof Reflect === "object");
Parent
Parent of Reflect
is Object.prototype.
console.log(Reflect.getPrototypeOf(Reflect) === Object.prototype);
Purpose
The Reflect
object is used as namespace
for functions related to JavaScript the language.
Reflect
's methods typically:
- Provides a function form of operators. For example,
Reflect.get(obj, key)
is the same asobj[key]
- Provide a more strict/improved version of existing methods. For example,
Reflect.getPrototypeOf(obj)
is same asObject.getPrototypeOf(obj)
, but will throw error if obj is not a object type.
Properties
- ownKeys
[see Reflect.enumerate]enumerate