Skip to content

Instantly share code, notes, and snippets.

@techanon
Created November 17, 2017 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techanon/ea2b4024d976814d4d68f78835fafc90 to your computer and use it in GitHub Desktop.
Save techanon/ea2b4024d976814d4d68f78835fafc90 to your computer and use it in GitHub Desktop.
Proxy protocol on the fly.
class T {
constructor(){
this.value = 'test';
}
test() {
return this.value + '-amend';
}
wrap() {
return proxy(this.test).bind(this);
}
}
function proxy(target) {
return new Proxy(target,{apply(T,that,args){ return T.bind(that)()+'-proxy'; }})
}
// let t = new T();
// t.test();
// >> 'test-amend'
// t.wrap()();
// >> 'test-amend-proxy'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment