Reflect API provides abstract operations, remaining behind JavaScript idioms. The primary purpose is to provide a reasonable way to redirect actions caused by Proxy traps . All Reflect methods correspond to the signature of proxy traps with the same name, so you can use new Proxy(target, Reflect) to create an object with identical behavior as the target object - everything will be redirected, including special JavaScript quirks.
This is especially important for getters and prototypes, since the third argument to many methods is the "receiver"
This value is provided for the target call if a getter is encountered.
Consider the following code:
var target = { get foo() { return this.bar; }, bar: 3 }; var handler = { get(target, propertyKey, receiver) { if (propertyKey === 'bar') return 2; console.log(Reflect.get(target, propertyKey, receiver));
When you write Proxy , you expect it to fully cover the target β and there is no idiomatic way to do this without Reflect .
In addition, operators as functions are convenient for programming a functional style.
source share