Last active
December 27, 2019 02:21
-
-
Save MatMercer/29a4816321b162e5ef9dc902d3efa6a1 to your computer and use it in GitHub Desktop.
Simple way of having a clean code in JS using object literals
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
var capitalByState = { | |
'MG': 'Belo Horizonte', | |
'PR': 'Curitiba', | |
'SP': 'São Paulo' | |
} // Allocated only one time and the data isn't INSIDE the function | |
// so 'capitalByState' can come from a external source! | |
var States = {}; | |
States.getCapitalCity = state => capitalByState[state] || 'Not Found'; // Again, allocated only one time, simulates static | |
States.getCapitalCity('PR') // Curitiba | |
States.getCapitalCity('??') // Not Found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment