I agree that isArray
's behavior is weird. But I really don't think it warrants a new trap.
Proxies already have certain other restrictions on which behaviors they are allowed to customize - the typeof
example is already mentioned, but there's also, for example, the [[IsExtensible]] trap, which is required to return the same value as that trap on the underlying object.
So there's always certain things that you need to know when establishing your Proxy - you can't blindly make a Proxy from an arbitrary target and then try to customize its behavior to act completely like something else after-the-fact. You really do need to figure out certain details of what you're going to be pretending to be when you set up the Proxy. "Whether you are going to be pretending to be an array" is only one example among several of things you need to know up front.
(You mentioned that new Proxy(Array.isArray(thing) ? thing : {thing})
wouldn't work for you, but I don't understand why - all you said is that isArray
might be patched, but of course new Proxy
might be patched; you generally can't be defensive against earlier-running code patching stuff.)