Created
December 13, 2017 05:49
-
-
Save ORESoftware/757dd6285d554f4f52ae415fd39141a5 to your computer and use it in GitHub Desktop.
Access context value via Proxy of prototype method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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