Michael Geary wrote: >> When you create a named function is is basically a static >> object stored in funcname of the scope it was defined in. >> when you declare a var in a function it is also a static >> object attached to the function object. As such mydata is a >> single static object and effectively a single object in the >> global space of objects. So repeated calls to funcname that >> set mydata will result in the last calls values be stored into mydata. >> >> With the anon function, you are actually creating multiple >> functions each with its own mydata variable defined within >> each anon function. The var statement DOES NOT work like it >> does in C where the variable is created on the stack and is >> unique to that function call at runtime. >> >> Does this sound right? > > No, not at all. (Sorry!) > > The var statement DOES work just like a variable declaration in C. A > variable declared in a function is not attached to the function object. It > is created when the function is *called*, the same as in C, and free for > garbage collection when the function returns - unless there is an > outstanding reference to it as in the case of a closure. Even when there is > a closure, a variable is still specific to a single invocation of the > function in which it is declared. > > Also, it makes no difference if a function is named or anonymous. The scope > rules are identical for either kind of function. > > I'll go look at the original problem, but I just wanted to correct this > first.
Thank you Mike, I appreciate the correction. I was a little dumb founded by the only explanation that I could come up with and decided over dinner that I should test it out an verify it. I probably should have done that before posting. All the good thoughts seem to come after hitting Send! -Steve _______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
