1 Replies - 689 Views - Last Post: 27 January 2014 - 10:27 PM

#1 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,867
  • Joined: 12-December 12

Closures, simply

Posted 27 January 2014 - 05:53 PM

The following is one of the clearest, simplest, descriptions of closures that I have come across:

kirupa.com

Closures are one of the most confusing aspects of Javascript for beginner (and even experienced..) JS programmers. Recommended reading.

Following this, a slightly more detailed, but still excellent, article is to be found here:

Javascript Closures for Dummies (web archive)

Is This A Good Question/Topic? 2
  • +

Replies To: Closures, simply

#2 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: Closures, simply

Posted 27 January 2014 - 10:27 PM

Great find.

The first link explained alot of what I didn't quite get about closures and using nested functions.

Summary:

http://www.kirupa.com said:

If there is only [one] thing you take out of all of this, remember the following: The most important thing closures do is allow functions to keep on working even if their environment drastically changes or disappears. Any variables that were in scope when the function was created are enclosed and protected to ensure the function still works. This behavior is essential for a very dynamic language like Javascript where you often create, modify, and destroy things on the fly. Yay!

This post has been edited by laytonsdad: 27 January 2014 - 10:31 PM
Reason for edit:: fixed quote grammar

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1