• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

call object per string

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, so should I do something like that:




Is this better ?
 
Eric Pascarello
author
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic