his tutorial explains closures so that a regular programmer can understand them - using working JavaScript code. It is not for gurus nor functional programmers. Closures are not hard to understand once the core concept is grokked. However, they are impossible to understand by reading any academic papers or academically oriented information about them! This article is intended for programmers with some programming experience in a main-stream language, and who can read the following JavaScript function Most JavaScript programmers will understand how a reference to a function is returned to a variable in the above code. If you don't, then you need to before you can learn closures. A C programmer would think of the function as returning a pointer to a function, and that the variables sayAlert and say2 were each a pointer to a function. There is a critical difference between a C pointer to a function, and a JavaScript reference to a function. In JavaScript, you can think of a function reference variable as having both a pointer to a function as well as a hidden pointer to a closure. The above code has a closure because the anonymous function function() { alert(text); } is declared inside another function, sayHello2() in this example. In JavaScript, if you use the function keyword inside another function, you are creating a closure. In C, and most other common languages after a function returns, all the local variables are no longer accessible because the stack-frame is destroyed. In JavaScript, if you declare a function within another function, then the local variables can remain accessible after returning from the function you called. This is demonstrated above, because we call the function say2(); after we have returned from sayHello2(). Notice that the code that we call references the variable text, which was a local variable of the function sayHello2().
3 USD InStock
TripleClicks is the home of 12,130,142 Members in 195 countries worldwide!

Create an account

NOTE! By submitting this registration, you are acknowledging that you have read and agree to the TripleClicks Privacy Policy.

Join FREE today

Account created

You're now a TripleClicks member! Now is a great time to get some TCredits, which are used to bid on Pricebenders auctions, play Eager Zebra games and more!

Continue to TripleClicks

Get some TCredits now!

What are TCredits? They're used for bidding in Pricebenders™ auctions, playing Eager Zebra™ games, downloading TC Music, listing stuff you no longer need for sale at TripleClicks, and more! Learn more about TCredits.

Billing Info

Payment Info

ORDER TCREDITS MAYBE LATER

50 TCredits are now in your account--ready for you to use! We've also dispatched a quick order confirmation email to you. Thank you!

CONTINUE TO TRIPLECLICKS
The requested item is no longer active.
Similar Items
More Results