Issue
I have next function
var hideAll = function() {
// code
return ///...
};
And I am using this function like callback in another function.
When I am using it like
function (params, hideAll) {}
all working well, but when I am using
function (params, hideAll() ) {}
all not working well!
So my question is, what is difference between hideAll
and hideAll()
function executions?
Solution
hideAll
– this is a reference to the function
hideAll()
– this is execution of the function, its result
function (params, hideAll) {}
is a correct function definition,
whereas function (params, hideAll() ) {}
is not – you are unable to call another function in function definition.
However you could still write the following valid code:
var hideAll = function() {
// code
return ///...
};
var functionWithCallback = function(callback){
callback();
}
var closureReferringHideAll = function(){
hideAll();
}
// The following two lines will do exactly the same in current context,
// i.e. execute hideAll.
functionWithCallback(hideAll);
closureReferringHideAll();
Answered By – Li0liQ
Answer Checked By – Pedro (BugsFixing Volunteer)