Skip to content

Instantly share code, notes, and snippets.

@pcast01
Created August 11, 2019 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcast01/5b10c4f1a5f43817f7587604cce22b6f to your computer and use it in GitHub Desktop.
Save pcast01/5b10c4f1a5f43817f7587604cce22b6f to your computer and use it in GitHub Desktop.
function factory using closures.
function dwightJob(title) {
return function(prefix) {
return prefix + ' ' + title;
};
}
var sales = dwightJob('Salesman');
var manager = dwightJob('Manager');
alert(sales('Top')); // Top Salesman
alert(manager('Assistant to the Regional')); // Assistant to the Regional Manager
alert(manager('Regional')); // Regional Manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment