You need your handler to implement the get () hook and return the associated versionprom.then
var prom = new Promise(function(resolve, reject){resolve(42)});
var promProxy = new Proxy(prom, {
get: function(target, prop) {
if (prop === 'then') {
return target.then.bind(target);
}
}
});
promProxy.then(function(response){console.log(response)});
Please note that if you just want to proxy all means of access, the function getwill look like this:
var promProxy = new Proxy(prom, {
get: function(target, prop) {
var value = target[prop];
return typeof value == 'function' ? value.bind(target) : value;
}
});
bind ensures that the function will not be called incorrectly when dealing with Native objects such as Promises or the console.
: / Proxies, Harmony-Reflect, .