Javascript Reflection.
JavaScript has a Reflect object. It is not a function object and doesn’t have an internal method. Reflect is not a constructor. This, Reflect object, provides some static functions which we used in the proxy handlers. Let’s see the static reflect methods
Apply,construct,defineProperty,deleteProperty,enumerate,get,getOwnPropertyDescriptor,getPrototypeOf,isExtensible,ownKeys,preventExtensions, set,setPrototypeOf
Let's check with some reflect static methods with examples.
Reflect.apply ( target, thisArgument, argumentsList)
The Reflect.apply() method is used to call a function using the specified parameter.
Reflect.deleteProperty ( target, propertyKey )
Reflect.deleteProperty() method allows to delete properties of the object.
Reflect.get( target, propertyKey[, receiver]
)
The Reflect.get() method is used to get the property from an object as a function. The first argument is the object and the second argument is the property name.
Let's see the example with Reflect and Proxy handler.
In Proxy Handlers, instead of returning target[prop], we can use Reflect.get() static method to return. You can see that in the below example:
This is the best way to return the target index in Proxy.