Created
August 11, 2019 13:12
-
-
Save pcast01/5b10c4f1a5f43817f7587604cce22b6f to your computer and use it in GitHub Desktop.
function factory using closures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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