Possible Duplicate:
Dynamic object property name
I have a function that I need to call based on a user inputted data.
So for example, I have:
models.cat
models.dog
Now, I want to be able to call models.[my_str]
where my_str = "snake"
. So the computer would think it is trying to execute models.snake
. Is there a way to do this in javascript or better yet coffeescript?
You should be able to call it like so:
models[my_str]();
This should work in both Javascript and Coffeescript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With