Skip to content

Instantly share code, notes, and snippets.

@Cheffheid
Created July 22, 2016 00:26
Show Gist options
  • Save Cheffheid/1372bff50181122fa1808935221f8c49 to your computer and use it in GitHub Desktop.
Save Cheffheid/1372bff50181122fa1808935221f8c49 to your computer and use it in GitHub Desktop.
Basic Closure
function greeting( subject ) {
var message = "Hello %s!";
// hello() will have access to the message variable in the greeting() scope.
function hello() {
return message.replace("%s", subject);
}
return hello();
}
var world = greeting("World");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment