According to the ECMAScript spec, obj.[[Get]] is resolved as follows:
- First check whether an object has the key (GetOwnProperty)
- If it does not, defer to [[Get]] of obj’s prototype.
- […] (other steps omitted)
However, the spec for proxy.[[Get]] performs the following:
- […] (some steps omitted)
- If the trap is for [[Get]] is missing, defer to target.[[Get]].
This leads to the following inconsistency when combined with getPrototypeOf: an object can be considered an instance of some type T, but have no methods of that type.
Example as follows:
var o = {};
var p = new Proxy(o, {
getPrototypeOf(target) { return Array.prototype;}
});
console.log(p instanceof Array) //true
console.log(p.push) //undefined
Technically this behavior can be fixed by writing a [[Get]] handler, but this will likely push the performance down to unusable levels*.
* Experimenting on a module system inspired by ruby's. This suggests that every module function call will run through 1 or more proxy.[[Get]]s, which cuts performance to at least 1/10. Very crude benchmarks suggest 130× (instantiation) - 500× (function call) performance penalty for my own implementation.