I heard today that:
it is possible to access a local variable of a function since everything in JavaScript is global.
As far as I know, you can't access a local variable from outside of the scope of the variable.
For example:
function f()
{
var myvar = "something";
}
myvar = "c"; // i'm not accessing myvar in f();
I also heard that it's possible to use for(var i in window) to access myvar. I want to confirm it is not possible since I'm not the author of the language.
Updated:
I asked him a code snippet, and here's what I have received.
var person = {
whoIs : function()
{
var name = "name";
return name;
}
};
var str = "TEST:\n";
for(var n in person)
{
str += n;
str += " = [" + person[n] + "]\n";
}
// perform regular exp. to get the value of name variable.
alert(str);
It's not accessing the variable.. it's simply printing how the function looks like...