Created
August 26, 2015 10:31
-
-
Save trovster/a30c20a0cbd0b2c5a01c to your computer and use it in GitHub Desktop.
How can I get dynamic variable without eval?
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
<script type="text/javascript" id="bowling--js"> | |
var bowling_options = [1,2,3,4,5]; | |
</script> | |
<script type="text/javascript" id="restaurant--js"> | |
var restaurant_options = ['a','b','c']; | |
</script> |
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
$(['bowling', 'restaurant']).each(function (type) { | |
eval(type + '_options'); // how can I avoid this? | |
}); |
Thanks Rich. I have migrated the code to what you have suggested. Works :)
great!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could do:
or without jQuery: