about semantic web, software architecture and life in general

Post details: Closures in JavaScript

2008-01-09

Permalink 00:25:44, Categories: Web development, Software Development   English (EU)

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.

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

This post has 21 feedbacks awaiting moderation...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, a, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

captsolo weblog

See also:

May 2012
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
  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      
Last comments

Search

Gallery

www.flickr.com
captsolo's items Go to captsolo's photostream

Misc

Syndicate this blog XML

powered by
b2evolution
Page served in 0.434 seconds

Valid XHTML 1.0! Valid CSS! Valid RSS! Valid Atom!