More information about the Underscore mailing list

[_] jQuery losing the scope!

Tim Beadle tim.beadle at gmail.com
Fri Dec 11 14:33:32 GMT 2009

2009/12/9 Alex Francis <alex.francis at gmail.com>:
> Just to be crystal clear - this statement in your original snippet at line 4
>
>    var vid_bg_img = null;
>
> is NOT declaring a global variable. It's inside a function
> declaration, so the variable is scoped to that function. Since you're
> also declaring some other functions within this function, they will
> also be able to see your variable, but it's not global. Might be worth
> reading about closures in javascript e.g.
> http://www.jibbering.com/faq/faq_notes/closures.html

Here's a couple more good articles on scope:
http://www.digital-web.com/articles/scope_in_javascript/
http://robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/

Also, running your scripts through jslint.com (and learning to code
within its strictures) is A Good Thing.

Cheers,

Tim