I was using proxy get
method fine. Then I tried using it on a function and quickly realized I needed to use the apply
method. This simple example is not working. It never enters apply.
Node looks to support apply https://node.green/#ES2015-built-ins-Proxy--apply--handler. Not sure what I'm doing wrong.
var Foo = {
runme: function() {
return 1;
}
};
var Magic = {
Foo: Foo
};
Magic.Foo = new Proxy(Object.assign({}, Magic.Foo), {
apply: function(target, thisArg, argumentsList) {
// never gets in here
console.log('Proxying function call');
console.log(target);
return 2;
}
});
console.log(Foo.runme()); // outputs 1
console.log(Magic.Foo.runme()); // outputs 1
I tried both Proxy on Magic.foo
directly and via the Object.assign
to see if it needed to be its own object or not. Neither worked.