Last active
October 18, 2021 18:30
-
-
Save evinism/eff97c05e7835f04e27dcf3006b1b848 to your computer and use it in GitHub Desktop.
cjsp3
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
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