You can, of course, replace the default object to assign a property value, for example, to
with (pseudoGlobal) eval("x=12")
but not for creating a property. If the property is not found in the current stack of execution contexts, it is created in the global object. That is all there is. You can try some weird things as well:
//global code var globalvars = {}; for (i in this) globalvars[i] = null; with (pseudoGlobal) eval("x=12") for (i in this) if (!(i in globalvars)) { pseudoGlobal[i] = this[i]; delete this[i]; }
If you need global bindings, try:
var globalvars = {}; for (i in this) globalvars[i] = this[i]; with (globalvars) eval("x=12")
this way the bindings will be changed in globalvars. Please note that this shallow copy will prevent only one beat level from changing.
source share