Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 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
You can’t perform that action at this time.