JS: Reflect (namespace)
(new in JS: ECMAScript 2015)
What is the Keyword “Reflect”
Reflect is the value of the property key "Reflect" of the Global Object
.
console.log(globalThis["Reflect"] === Reflect);
Type
typeof Reflect === "object"
Parent
Parent of Reflect is Object.prototype.
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.