Is it possible to define a handler property that intercepts typeof proxyObject
? None of the listed traps at Mozilla list it as an interception.
Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs, and so on. You create a Proxy with two parameters: target : the original object which you want to proxy. handler : an object that defines which operations will be intercepted and how to redefine intercepted operations.
Proxy is an object in javascript which wraps an object or a function and monitors it via something called target. Irrespective of the wrapped object or function existence. Proxy are similar to meta programming in other languages.
ES6 implements intercession form of meta programming using Proxies. Similar to ReflectAPI, the Proxy API is another way of implementing meta programming in ES6. The Proxy object is used to define custom behavior for fundamental operations. A proxy object performs some operations on behalf of the real object.
Proxy Measures A proxy is an indirect measure of the desired outcome which is itself strongly correlated to that outcome. It is commonly used when direct measures of the outcome are unobservable and/or unavailable.
It is not possible to intercept typeof
. The type of the proxy object will be the same as the proxy target.
You can see this in the spec here: http://www.ecma-international.org/ecma-262/7.0/#sec-typeof-operator-runtime-semantics-evaluation with the important parts of the table being
A proxy is an object, and whether it implements [[Call]]
depends on the type of target
passed to the proxy at creation time. That you can see in http://www.ecma-international.org/ecma-262/7.0/#sec-proxycreate Step 7. So if you pass it a function (they all implement [[Call]]
), then the proxy will too, and the proxy will return function
for typeof
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With