Calling javascript function with an objectstring in dot notation

Viewed 4400

Suppose I have the string:

var string = "function";

With

window[string];

I can call a function with the name of "function".

But, when I have:

var string2 = "function.method.weHaveTogoDeeper";

it should call

window["function"]["method"]["weHaveTogoDeeper"]

I can't do:

window[string2]

in this case. I dont know the number of "." in the string, so I need some kind of routine.

3 Answers
Related