Created
September 4, 2016 20:23
-
-
Save DrewML/c195daba750e50566f1d2fd61d3515c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const window = { | |
a: 1 | |
}; | |
global = new Proxy(global, { | |
get(target, prop, receiver) { | |
if (target[prop] !== undefined) { | |
return target[prop]; | |
} | |
return window[prop]; | |
} | |
}); | |
// Will be caught by proxy | |
console.log(global.a); | |
// Will not be caught by proxy. I'm _guessing_ the | |
// [[Get]] slot isn't being used when resolving against the | |
// global environment record? | |
console.log(a); |
This file contains hidden or 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 works as intended. Referencing `a` in the top-level | |
// calls the getter on the `global` object | |
Object.defineProperty(global, 'a', { | |
get() { | |
return 'this works'; | |
} | |
}); | |
console.log(a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment