n00b question

Hi. I need to know how to call a function within a function.

function parent() {
function child() {
//code here
}
}

//how do i call child from outside of parent?

In your example, there is no way to call the child function. It’s something you could do in JavaScript to emulate the private variables of other languages.

If you want it to be publicly accessible, you could do something like this:


function parent() {
    function child() {
        // code here
    }
    parent.child = child;
}

…But it’s important to remember that the “child” function is not created until the “parent” function is called.


function parent() {
    function child() {
        // code here
    }
    parent.child = child;
}

parent.child(); // throws an error

parent(); // "child" function is created and assigned to parent.child
parent.child(); // works!

parent(); // "child" function is rebuilt and reassigned
parent(); // "child" function is rebuilt and reassigned
parent(); // "child" function is rebuilt and reassigned
parent(); // "child" function is rebuilt and reassigned