-2

Now I use this method to call functions inside a Namespaces:

eval('Admin.' + section + '.' + action + '()');

But I don't like use eval, I need to call methods in different namespaces creating the call using string given me from JSON, but I think this is not good system, because eval it's dangerous.

Any other form to make this works? Thanks!

Derek 朕會功夫
  • 88,688
  • 41
  • 174
  • 241
Zenth
  • 739
  • 2
  • 7
  • 23
  • possible duplicate of [How do I dynamically call a JavaScript object's method](http://stackoverflow.com/questions/5112793/how-do-i-dynamically-call-a-javascript-objects-method) – Esailija Jul 15 '12 at 18:31

1 Answers1

6

You can use the [] operator to do that:

Admin[ section ][ action ]();
Pointy
  • 389,373
  • 58
  • 564
  • 602
  • is called "square bracket notation", see: https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects#Objects_and_properties – ZER0 Jul 15 '12 at 18:12