Here, Reflect is being used to take care of the "default" case of accessing an array using a normal numerical index.
The rest of the time we're abusing the fact that any key in arr[key] form gets coerced into a string, so can be parsed into whatever we like once it reaches the getter/setter in a Proxy handler.
I posted this elsewhere, but here's an example use-case:
Let's say you want to use arrays as accessors, like this:
You can use
ProxyandReflectto achieve it:Here,
Reflectis being used to take care of the "default" case of accessing an array using a normal numerical index.The rest of the time we're abusing the fact that any
keyinarr[key]form gets coerced into a string, so can be parsed into whatever we like once it reaches the getter/setter in aProxyhandler.this looks very helpful