Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created July 21, 2013 20:13
Show Gist options
  • Select an option

  • Save PatrickJS/6049802 to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/6049802 to your computer and use it in GitHub Desktop.
Closures: data hiding with closures, something that encloses it's lexical scope and holds on to variables as a way of passing behavior around. It's behavior that has hidden storage
// Closures
function getCtr() {
var i = 0;
return function() {
console.log(++i);
};
}
var ctr = getCtr();
ctr(); //=> 1
ctr(); //=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment