Created
October 26, 2010 20:00
-
-
Save bentruyman/647655 to your computer and use it in GitHub Desktop.
Dynamic property names in object literals
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
| // Can we get something like this?? | |
| var howManyRainbows = 'double'; | |
| var rainbow = { | |
| (howManyRainbows): true | |
| }; | |
| if (rainbow.double) { | |
| alert('What does it mean?'); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, just as @getify said, there are other ways of accomplishing this in JavaScript, but I'd like to see if anyone else finds something like what I'm doing useful.
For example:
I'd rather construct my object in one fell swoop, instead of:
@Singles, my apologies for being vague in my question.