Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created March 25, 2012 22:43
Show Gist options
  • Save mahmoud/2200504 to your computer and use it in GitHub Desktop.
Save mahmoud/2200504 to your computer and use it in GitHub Desktop.
brief closure demonstration
var greet = function(greeting) {
var full_greeting = greeting+', ';
var greet_name = function(name) {
console.log(full_greeting + name);
}
return greet_name;
}
var hello = greet('hello'); // builds a greeting function, prints nothing
hello('stephen'); // does the actual printing
var guttentag = greet('guttentag');
guttentag('sarah');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment