To understand the callback function, you first know that in JavaScript, the function is also an object, it can be assigned to a variable, or it can be passed as a parameter to another function. Like what:
var add=function(b) { Console.log (a+b);}; // 3Add (+);
A variable add is defined here, and an anonymous function is assigned to the variable;
The next demonstration is to pass the function as an argument to another function, in other words: Place one function in the argument list of another function (such as parent), pass it as a parameter to the parent, and execute it somewhere in the parent function body. In fact, this is the callback function. Look at a little chestnut:
var fun=function (callback) { var a=1,b=2,c=3; var s=callback (A,b,c); return S;};
// call fun var t=fun (function (x, y, z) { Span style= "color: #0000ff;" >return (X+y+z);}); // 6 console.log (t);
The first is to define the function Fun,fun there is a parameter callback (name can be arbitrarily), before calling the fun function, do not know what the callback is, the call is passed to it is a functional function (x, y, z) {return (x+y+z);} As a parameter, the value of S is the value that is added to the returned three number. This is a simple procedure to use a callback function.
Understand the callback functions in JavaScript