-1

How to call a nested function with only a string? eg:

function oot(wha)   {
        function inn(wha)
          {
          First.innerHTML+="Inner ["+wha+"]";
          }
   oot.inn = inn;
   Second.innerHTML+="Outer ["+wha+"]";
                    }
 oot("1");  
 oot.inn("2");  //works okay
 window["oot"]("3");    //works okay
 window["oot.inn"]("4");    //<The problem, doesn't work.
 window["oot"]["inn"]("4");  //Works, thanks. 

Edited to make the code more readable, and show a solution.

IF there is no way to make this work with a single string i can probably make do, but i will leave the question unanswered for a few hours to see if there is another solution.

2
  • Could you indent your code properly? Commented Jul 13, 2022 at 10:04
  • oot.inn is not a property of the global object. Should be window.oot.inn or window["oot"]["inn"]. Commented Jul 13, 2022 at 10:06

1 Answer 1

0

You can reference nested Objects like this:

window["oot"]["inn"]("4");

or

window.oot.inn("4")
Sign up to request clarification or add additional context in comments.

1 Comment

They can, but the problem is that they have the string oot.inn and need to transform it to that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.