javascript - Access a var defined inside a closure from outside (i.e. the scope where the closure was defined) -


for background, playing through untrusted, javascript-based programming game core mechanic editing code modify game world progress forward. have solved levels "intended" way modifying variables given in local scope using documented in-game api. however, wondering if there "unintended" ways modify game state/game definition fishing around.

a lot of game has code follows (evaluated in window scope):

function foo() {     var bar = 1234; } 

i understand can access foo scope referring window.foo. there way can access bar inside foo though not explicitly exposed?

to clarify, above code evaluated me (in window scope, believe, can @ least reference foo). can not change evaluated. (i suppose redefine foo if wanted, , bypass lot of restrictions, that's tangential current direction of questioning.) rather, goal is, given has been evaluated, modify in place (such setting new value bar).

thanks in advance!

the short answer no.

it's not possible access local variable outside of it's scopes/closures (note due closures, there may more 1 scope can access single local variable).


for long answer, see answer description of how scopes work: javascript can't access private properties.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -