I would like to understand why it is not possible to create an "universal" forward proxy with ES6. By "universal" I mean that the proxy target may be any kind of non-primitive value (including function) with the same proxy declaration (constructor + handlers).
case 1:
var o = function myCtor() {}
var p = new Proxy({}, {
construct: function(target, ...args) {
return Reflect.construct(o, ...args);
}
});
console.log(new p); // TypeError: p2 is not a constructor
case 2:
var o = {}
var p = new Proxy(function() {}, {
ownKeys: function(target) {
return Reflect.ownKeys(o);
}
});
console.log(Object.keys(p)); // TypeError: 'ownKeys' on proxy: trap result did not include 'arguments'
Case 1 works properly when I use function(){} as Proxy target (instead of {}) but then, case 2 do not works any more.
Thanks for your help.