Easy Proxy
Base on direct-proxies but simplified and without verification. EasyProxy allows for simplified creation of Proxies.
npm install easy-proxy
Traps
Names modified for brevity, argument order normalized, fwd
and target
provided. A handler can be reused much more easily since the target is always provided.
var proxied = EasyProxy(target, {
fix: function(fwd, target){},
delete: function(fwd, target, name){},
names: function(fwd, target){},
keys: function(fwd, target){},
enumerate: function(fwd, target){},
owns: function(fwd, target, name){},
has: function(fwd, target, name){},
get: function(fwd, target, name, rcvr){},
set: function(fwd, target, name, rcvr, val){},
describe: function(fwd, target, name){},
define: function(fwd, target, name, desc){},
apply: function(fwd, target, args, rcvr){},
construct: function(fwd, target, args){},
});
Usage
Any traps not provided in the handler will default to forwarding to the target.
The first parameter, fwd
is a function that when called will forward the action to the target and return the result. The forward function also has two properties to modify what it does
- forward.target - Change this to forward to a different target.
- forward.args - An array of the arguments that will be forwarded (the sames ones given to your function minus
target
and rcvr
)