我正在与Proxy合作,并且一直在尝试以下操作:
class Foo() {
hello() { return 'there'; }
}
let handler = {
get: function(...args) {
console.log('get', args);
return 'gotten';
},
apply: function(...args) {
console.log('apply', args);
}
}
let proxy = new Proxy(new Foo(), handler);
proxy.hello() // # => 'there'
proxy() // # => proxy is not a function
我知道apply
仅用于代理函数,而不是对象实例,因此我知道正在发生的事情是预期的行为-但这不是我想要的。我想要的是能够调用代理。
我想成为可能的事情清单:
// proxy is an instance of a yet-to-be-determine object, or something that acts like one.
proxy.hello(); // works
proxy.someGetter; // works
proxy(); // not sure how to get this working?