Skip to content

Instantly share code, notes, and snippets.

@evinism
Last active October 18, 2021 18:30
Show Gist options
  • Save evinism/eff97c05e7835f04e27dcf3006b1b848 to your computer and use it in GitHub Desktop.
Save evinism/eff97c05e7835f04e27dcf3006b1b848 to your computer and use it in GitHub Desktop.
cjsp3
function only(definedItems){
return new Proxy({}, {
has(_, prop){
return !definedItems.includes(prop);
},
get(_, prop){
throw new Error("Referenced variable " + prop.toString() + " out of scope!");
},
set(_, prop){
throw new Error("Referenced variable " + prop.toString() + " out of scope!");
}
});
}
const a = 'available';
const b = 'unavailable';
with (only['a', 'console']) {
console.log(a); // "available"
console.log(b); // Throws!!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment