So heres the basic outline
function x(){
// some code
function y(){
//some more code
}
}
function z(){
// how do i call function y?
}
I tried
function z(){
window[x][y];
}
and
function z(){
x();y();
}
neither works!
So heres the basic outline
function x(){
// some code
function y(){
//some more code
}
}
function z(){
// how do i call function y?
}
I tried
function z(){
window[x][y];
}
and
function z(){
x();y();
}
neither works!
1:
2:
3:
the global namespace is still as it was before this code
Lots of code, not much explanation.
The above declares y inside x, so it is created as a property of x's variable object each time x is called. y can only be accessed from inside x unless code inside x makes it available from elsewhere.
To call y from inside z, it must be available on z's scope chain. That can be done by passing it in the function call (making it a property of z's variable object) or making it a property of some object on z's scope chain.
If the function is to be available to both functions, it makes sense to declare it where it can be accessed by both x and z, or initialize z in such a manner that y is available. e.g.
In the above, x and z both have access to the same y function and it is not created each time x is called. Note that z will be undefined until the code assigning to x is executed.
Note also that y is only available to x and z, it can't be accessed by any other function (so y might be called a private function and x and z might be called privileged functions).