J
John Davison
When you have the following:
function foo() {
var bar = 10;
// do some other stuff
}
It is my understanding that bar is *not* a property of function object
foo. Now, when you have the following type of code
function foo() {
var bar = some_user_input();
var f = function() {
// do something with bar
};
// set f to get called by some async method
}
when f() runs bar will be in scope. With an asyncronous method, f() will
get called some time later. Assume that foo() is called a first time, and
f() is set to execute eventually. What happens to bar if foo() gets
called before the first f() executes? Does the first foo() have bar on
its stack? Or do the two calls to foo() have the same stack?
I guess my question is: in that context is bar treated like a property or
a local variable?
John
function foo() {
var bar = 10;
// do some other stuff
}
It is my understanding that bar is *not* a property of function object
foo. Now, when you have the following type of code
function foo() {
var bar = some_user_input();
var f = function() {
// do something with bar
};
// set f to get called by some async method
}
when f() runs bar will be in scope. With an asyncronous method, f() will
get called some time later. Assume that foo() is called a first time, and
f() is set to execute eventually. What happens to bar if foo() gets
called before the first f() executes? Does the first foo() have bar on
its stack? Or do the two calls to foo() have the same stack?
I guess my question is: in that context is bar treated like a property or
a local variable?
John