MacBook, defective by design banner

title:
Put the knife down and take a green herb, dude.

descrip:
One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com

Self-Pimpin':
Member of an email list?
You need The Digest Handler!!


FOR ENTERTAINMENT PURPOSES ONLY!!! Back-up your data and always wear white.
URLs I want to remember:
* Atari 2600 programming on your Mac
* joel on software (tip pt)
* resume, mostly for Google * Regular Expression Introduction (copy)
* gpl xbrowser API for dhtml
* mulder (old css tutorial)
* Using CommonDialog in VB 6 * Free zip utils
* that hardware vendor review site I forget about is here * Javascript 1.5 ref
* Read the bits about the zone * w3c.org index of HTML 4.01 elements
* Giant ASCII Textifier * Quick intro to Javascript
* Editable Firefox Page * Parsing str's in VB6
email if ya gotta, RSS if ya wanna RSS
 
 
Wednesday, January 11, 2012

http://stackoverflow.com/questions/111102/how-do-javascript-closures-work

Also a decent link from one of those answers, though the explanation is bit long.

http://jibbering.com/faq/notes/closures/

I think the one I like best, though, comes from here, even if the guy's a little snotty replying to one of the comments to his post:

I find the best way to explain them (and the way that I learned what they do) is to imagine the situation without them:

var bind = function(x) {
return function(y) { return x + y; };
}

var plus5 = bind(5);
alert(plus5(3));

What would happen here if JavaScript didn't know closures? Just replace the call in the last line by its method body (which is basically what function calls do) and you get:

alert(x + 3);

Now, where's the definition of x? We didn't define it in the current scope. The only solution is to let plus5 carry its scope (or rather, its parent's scope) around. This way, x is well-defined and it is bound to the value 5.

Labels:


posted by ruffin at 1/11/2012 12:17:00 PM
0 comments


All posts can be accessed here:


Support freedom
Last year o' posts:



Powered by Blogger furthurnet.org