This is a very basic javascript question:
after defining a function:
function a(){
alert("A!");
return function(){
alert("B!")
};
}
If i call the function:
a();
Only "A!" is alert; But if i recreate a new function:
var newFunc = a();
newFunc();
Both "A!" and "B!" are alerted.
Can someone explain why? Millions THX!!
This is extracted from p78, Object-Oriented JavaScript, Stoyan Stefanov, PACKT PUBLISHING
a()
creates a function, but doesn't call it. You can then call the function thata()
created, but just callinga()
doesn't do so.