Scopes, too! On Fri, Apr 29, 2011 at 8:23 AM, Slik <[email protected]> wrote:
> closures > > On Fri, Apr 29, 2011 at 4:20 PM, Tim Wienk <[email protected]> wrote: > > In short: > > A variable you create in one scope is available in all its child scopes: > > > > (function(){ > > var something = 1; > > (function(){ > > console.log(something); // Logs 1. > > })(); > > })(); > > console.log(something); // Reference Error: something is not defined. > > > > So doing `var self = this;` (I prefer 'self' over 'that'), will make > > `self` refer to `this`, which will be available in a child scope as > > well. > > > > To read more about it, and the actual *why* it works like that, I'd > recommend: > > http://www.amazon.de/Pro-JavaScript-MooTools-Mark-Obcena/dp/1430230541/ > > >
