I have a proxy handler like this:
let handler = {
get: function(target, name) {
let member = target[name];
if (typeof member === 'function') {
return function() {
//
}
}
return member;
}
}
Whenever a method is called on Proxy object:
var obj = {
foo: function() {
//
}
}
var p = new Proxy(obj, handler);
p.foo();
...It invokes the function that was returned from the handler
's getter. But the problem is, when the method is accessed rather than invoked like this:
p.foo;
The entire definition of the function is returned.
Is there any way by which I could check to see if the method is being accessed (p.foo
) or invoked (p.foo()
)? I am trying to achieve something like:
if (typeof member === 'function' && member.isBeingCalled()) {
return function() {
//
}
}
Also, in case of p.foo
, I would like to return the definition of member
instead of the function that handler's getter returns.