It is possible using the ES6 Proxy API:
var myObj = {};
var myProxy = new Proxy(myObj, {
get: function get(target, name) {
return function wrapper() {
var args = Array.prototype.slice.call(arguments);
console.log(args[0]);
return "returns: " + args[0];
}
}
});
console.log(myProxy.foo('bar'));
Browser compatibility is available on MDN. As of August 2017 all browsers (including Microsoft Edge) except Internet Explorer support it.
See this answer for a more complete look at Proxy.