+ 1

Does nesting a function inside a function makes the inner function private?

20th Jun 2017, 12:55 AM
DIY Mods
DIY Mods - avatar
3 Answers
+ 3
Yes and no. Typically you cannot access an inner function from outside the parent function. However, there are way that you can build your functions to give you some level of access to the inner function. For instance you can't access the function inner below: function outer() { function inner() { alert("hello"); } } inner() // undefined outer().inner() // undefined outer.inner() // undefined But if you build your function so that it exposes the inner function: function outer() { function inner() { alert("hello"); } outer.inner = inner; } outer(); // outer function needs to be called to create the outer.inner variable. outer.inner(); // now you have access to the inner function and the alert outputs hello.
20th Jun 2017, 1:17 AM
ChaoticDawg
ChaoticDawg - avatar
20th Jun 2017, 1:21 AM
Jamie Isaksen
Jamie Isaksen - avatar