| Author |
call object per string
|
nimo frey
Ranch Hand
Joined: Jun 28, 2008
Posts: 580
|
|
I have a common js-object:
I know, I can call property a via or via .
I want to do something like this:
But it does not work. How can I do that? Should I use eval or call() or something?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Never use eval.
It would be better if you namespaced it and not make it a global variable.
but if you have a thing against using the namespace, you can always use window
Eric
|
 |
nimo frey
Ranch Hand
Joined: Jun 28, 2008
Posts: 580
|
|
Thanks it works, but I how do I solve that, when using module-pattern:
I want to call Submodule by string:
Something like
does not work.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Becuase you are storing a result of a function to a variable and the function is not returning anything to store in that variable.
Eric
|
 |
nimo frey
Ranch Hand
Joined: Jun 28, 2008
Posts: 580
|
|
Oh, so should I do something like that:
Is this better ?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
That code appears to be the same as it was before.
Your code is the same as:
All of the stuff inside is local variables, there are no way you can access them.
If you want something to be accessed outside of it, you would have to return it.
|
 |
 |
|
|
subject: call object per string
|
|
|