JS: Reflect (namespace)
(new in ECMAScript 2015)
What is the Keyword “Reflect”
Reflect is the value of the property key "Reflect" of the Global Object
.
console.assert(globalThis["Reflect"] === Reflect);
Type
console.assert(typeof Reflect === "object");
Parent
Parent of Reflect is Object.prototype.
console.assert(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. e.g.
Reflect.get(obj, key)is the same asobj[key] - Provide a more strict or improved version of existing methods. e.g.
Reflect.getPrototypeOf(obj)is same asObject.getPrototypeOf(obj), but throw error if obj is not a object type.