I have following code:
let p = new Proxy([1, 2, 3], {
get: function() {
console.log('get')
}
})
console.log(p)
I think Proxy
should proxy everything about [1,2,3]
.
When I log
value, it should read value from [1,2,3]
, so the getter should be triggered.
But when I set a breakpoint in the getter, the breakpoint is not hit?
Why don't console.log
and console.table
trigger the getter function?
Calling console.log ( util.inspect with default opts) on an instance of a Proxy invokes the get trap with some built-in Symbols. (It also invokes the trap with "inspect" and "valueOf", which is different than browser behavior but doesn't seem as problematic.)
Make sure you are using the browser’s console (Ctrl + Shft+ J in Chrome) and not the fake console that FCC provides. That absolutely works. Weird how the FCC ‘console log’ just quit working. It was working fine for months and stopped about an hour ago.
Most of the time calling console.log () when the console is not yet active only results in a reference to the object being queued, not the output the console will contain. As a workaround you will need to either clone the information or serialize snapshots of it.
That's because you are logging the Proxy object itself.
The browser console has access to its internal state, which is an Object with two or three internal properties: [[target]]
, [[handler]]
and [[IsRevoked]]
.
You may note that Chrome does by default expands the [[target]]
in its collapsed message:
while Firefox choose to expose only the Proxy object by default (and doesn't expose an [[isRevoked]] internal, they set <target>
and <handler>
to null to signal revoked Proxies).
So as to how they are able to not trigger the trap, well they take the internal [[target]] shortcut and access directly to the original Object.
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