Creating a Function that can Remember Data

I recently released a tutorial about creating functions that remember data. This can also be referred as “retaining state”. This is a great feature of JavaScript and it reflects what I feel is one of the strengths of JavaScript.

This technique uses closure, but it uses it in a way that my not be intuitive, even to those that understand closure well. The basic idea is that your invoke a function that returns a function, and that returned function has access to (remembers) any data that was passed to it or establish at the time the function was returned.

This can be a powerful feature. Take a few moments and watch the tutorial and then tell me what you think.

Author: Steven Hancock

Steven has 20+ years experience in product development and 15+ years using JavaScript. He started learning JavaScript when it was a niche language used for minor affects on a web site. The growth and ubiquitous nature of JavaScript both excites and inspires him.

Currently he is President and lead Trainer at All Things JavaScript, a resource for anyone and everyone that hopes to increase their JavaScript skills.

Steven was the co-owner of Rapid Intake, an eLearning Authoring firm. While there he managed all development and professional service related activities. He was heavily involved in the initial development of Rapid Intake’s main product, which eventual lead to its acquisition in 2011. In addition to JavaScript, Steve has also dabbled in other web technolgies such as ActionScript, ASP, PHP, HTML, and CSS.