Archives for: January 2008
09.01.08
Closures in JavaScript
There are cases when you need to use JavaScript closures and there are cases when you accidentally create closures when you don’t need to. Here are some articles to help understand them:
“JavaScript Closures for Dummies” [blog.morrisjohns.com]
“JavaScript Closures” [jibbering.com]
“AJAX in Action: Appendix B - JavaScript for Object-Oriented Programmers” [java.sun.com]
Interesting & related:
“Closures and executing JavaScript on page load” - Simon Willison on chaining multiple onLoad events
“Private members in JavaScript” - Douglas Crockford on implementing private class members
TrimBreakpoint - a tricky use of closures to let you inspect local variables for a function from a popup breakpoint window.
A JavaScript closure preserves references to all the local variables after the function has finished.
If a function is defined within another function, a closure is created. Then the inside function (e.g. when called later, using a reference to it) can still access and modify variables of the outside function, even after the outside function has quit.
Note: this explanation is a very simplified view and you may want to consult articles referenced here for more detailed information.
CaptSolo :: All Blogs
See also:
- My homepage (captsolo.net)
- @CaptSolo on Twitter
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| << < | Current | > >> | ||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
Search
Gallery
www.flickr.com
|
Categories
Archives
- May 2008 (4)
- April 2008 (2)
- March 2008 (2)
- February 2008 (2)
- January 2008 (1)
- December 2007 (1)
- November 2007 (2)
- October 2007 (5)
- September 2007 (4)
- August 2007 (1)
- July 2007 (3)
- June 2007 (3)
- More...
- more...


