javascript - If code is placed within an anonymous function, why can I access it from the console? -
i've noticed meteor's production ready code concatenated, minified, , wrapped in anonymous function.
in theory, should make meteor object , methods inaccessible through dom / window object / console.
why can still access objects placed within anonymous function through console?
javascript function scoped, means outer function variables accessible (and editable!) inner functions. goes way global (window) variables. example:
(function() { window.t ='foo'; })();
if run code in console, see t
is, you'll see created/changed within function. meteor globally scopes few variables (meteor
, check
, etc.) can access them, in addition variables scope when create package. because each .js
file anonymous function & if didn't export variables, you'd have write in 1 big file. exporting variables need, project stays modular. hope helps!
Comments
Post a Comment