Closed blake-regalia closed 9 years ago
I think you didn't read the code well, index.js#L97 clearly shows that it's getting the other traps, createFunction only has "construct" and "apply" as arguments because that's what the old api was doing...
your code works perfectly fine...
var Proxy = require('harmony-proxy');
var simple = function() {
return 'called';
};
var proxy = new Proxy(simple, {
get: function(target, prop) {
return 'getting property '+prop;
},
});
dies with:
/Users/.../harmony-proxy/lib/index.js:92 return Proxy.createFunction( ^
TypeError: Proxy.createFunction called with non-function for 'call' trap at Object.createFunction (native) at new ProxyShim (/Users/.../harmony-proxy/lib/index.js:92:15)
Which means it needs apply
and construct
traps (which ES6 does not require for function targets!)
Was fixed with https://github.com/Swatinem/proxy/pull/3
but @Swatinem didn't update the npm package... (he also didn't fix travis yet, which is quite the shame)
change your package.json line to
"harmony-proxy": "Swatinem/proxy"
this will get the git repo version where it's fixed after doing a npm update
Ah, i see. Thank you!
I just released 0.1.0. Also added a test for that case, fixed some lints and the travis build. enjoy, and thanks for your interest in the project :-)
new Proxy(target, handler)
allows you to extend functions as if they were plain objects. For example, in ES6:However, this shim calls
Proxy.createFunction
, which only allows traps for calling and constructing the function, not any other traps.