Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created December 13, 2017 05:49
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 ORESoftware/757dd6285d554f4f52ae415fd39141a5 to your computer and use it in GitHub Desktop.
Save ORESoftware/757dd6285d554f4f52ae415fd39141a5 to your computer and use it in GitHub Desktop.
Access context value via Proxy of prototype method
// this is a little closer
const assert = require('assert');
const foo = function () {
console.log('this 1 => ', this);
assert.notEqual(this, v);
};
const v = {};
v.foo = new Proxy(foo, {
get: function (target, prop) {
console.log('target => ', target);
console.log('this 2 => ', this);
}
});
const x = Object.create(v);
x.zoom = 3;
x.foo();
const z = v.foo.five;
console.log('z => ', z);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment