JSFiddle - React, Tailwind, and code Playground
JavaScript
(function() {
'use strict';
console.clear();
//some empty class where I want to trap methods props
class X {
//..
}
let proxy = {
get: function(target, prop, receiver) {
console.log('get called: ',
'target:', target,
'prop:', prop,
'receiver:', receiver
);
//this is OK, if we are called as a method.
//but it isn't when called as .prop - because, obviously, we return a function here.
return function(...args) {
console.log('wrapper args:', args);
return 42;
}
},
};
let p1 = new Proxy(X, proxy);
//how to distinguish the two in the above proxy:
console.log(p1.test('some arg passed'));
console.log(p1.test);
})();