How can I strictly limit scope? I have tried wrapping and the Function class, but even though I can block self, window and globalThis by creating scope variables with the same names. Their items still persist and are usable within that code block.
One example which should be overkill but still allows self.location to be accessed.
(function () {
"use strict";
const foo = new Function('', "'use strict';const window=null, self=null, globalThis=null;console.log('global containers...',window,self, globalThis);return location");
console.log(foo());
})()
This produces....
global containers... null null null
Location {...}
...in google chrome. I want to understand how to limit or block scope from the general containing environment.
How can I have only my local scope available for block or function code?