Created
February 18, 2016 07:28
-
-
Save favio41/aa31b3c9a0539ea91171 to your computer and use it in GitHub Desktop.
This file contains 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
//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