Call Back Function
Hello there,
I happened to come up with a simplified concept of call back
function. It seemed to me somewhat complicated sometimes. I think some of you might
also come up against the same complication. It’s just what came into my mind.
If you find any inconsistency, please let me know. I’ll be happy to hear from
you. Now let me explain it.
Generally, first we declare/create a function. And then we
call it elsewhere. Like so.
// declare/create a callmeLateron () function
function callmeLateron(a, b){
return a + b;
}
// call the function
callmeLateron(2, 3);
But when we call the function first and then declare it
elsewhere, it’s called a call back function. Like so.
function operation(a, b){
var c = a + b;
var d = a - b;
// call declaremeLateron function
declaremeLateron(c, d);
// call back function
}
// declare declaremeLateron
function
function declaremeLateron(c, d){
console.log(c, d);
// 15, 5
}
// call operation
function
operation(10, 5);
Here we, first, call the ‘declarelmeLateron’ function within
‘operation’ function. And later on we declare the ‘declaremeLateron’ function.
So, declaremeLateron(c,d) is a call back function.
In a word,
declare first, call next = simple function
call first, declare next = call back function
That’s it. As simple as that. :D
See you.
Comments
Post a Comment