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:
";
for(var n in person)
{
str += n;
str += " = [" + person[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...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…