I now know this works:
function outerfunction(arg1, arg2, arg3) {
var others;
//Some code
innerFunction();
function innerFunction() {
//do some stuff
//I have access to the args and vars of the outerFunction also I can limit the scope of vars in the innerFunction..!
}
//Also
$.ajax({
success : secondInnerFunction;
});
function secondInnerFunction() {
// Has all the same benefits!
}
}
outerFunction();
So, I am not doing a ‘new’ on the outerFunction, but I am using it as an object! How correct is this, semantically?
There doesn’t appear to be anything wrong with what you’re doing.
newis used to construct a new object from a function that is intended as a constructor function. Withoutnew, no object is created; the function just executes and returns the result.I assume you’re confused about the closure, and how the functions and other variables belonging to the function scope are kept alive after the function exits. If that’s the case, I suggest you take a look at the jibbering JavaScript FAQ.