Skip to content

Instantly share code, notes, and snippets.

@favio41
Created February 18, 2016 07:28
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 favio41/aa31b3c9a0539ea91171 to your computer and use it in GitHub Desktop.
Save favio41/aa31b3c9a0539ea91171 to your computer and use it in GitHub Desktop.
//In this way we prevent 2 things:
// 1- Polute the global scope
// 2- The creation of the array name each time digitToName is called
var digitToName = (function(digit){
var names = ['one', 'two', 'tree']
return function(){
return names[digit];
}
}());
//Use
digitToName(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment