Created
September 21, 2017 22:12
-
-
Save itsthatguy/8d257ffe7150453cb3b729c37aa9ddd3 to your computer and use it in GitHub Desktop.
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
var userPreferencesDict = [ | |
'favoriteFood', | |
'favoriteColor', | |
'favoriteNumber', | |
]; | |
var userPreferences = [ | |
'pizza', | |
'seafoam green', | |
'42' | |
]; | |
function Dictionary (dict, array) { | |
return new Proxy([dict, array], { | |
get ([keys, values], key) { | |
const index = keys.indexOf(key); | |
return values[index]; | |
} | |
}); | |
} | |
const preferences = new Dictionary(userPreferencesDict, userPreferences); | |
preferences.favoriteFood; // => pizza | |
preferences.favoriteColor; // => seafoam green | |
preferences.favoriteNumber; // => 42 |
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 foo () { | |
// 0: Favorite Food | |
// 1: Favorite Color | |
// 2: Favorite Number | |
var userPreferences = [ | |
'pizza', | |
'seafoam green', | |
'42' | |
]; | |
} |
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
var userPreferences = [ | |
'pizza', | |
'seafoam green', | |
'42' | |
]; |
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
userPreferences[0] // Favorite Food | |
userPreferences[1] // Favorite Color | |
userPreferences[2] // Favorite Number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment