In C-like languages, it is usually passed by function pointer/reference.
jquery also provides a similar callback function mechanism. But it's still worth mentioning how to pass the callback function correctly.
1. Callback without parameters
Where myCallBack is the function name. Functions are the basis of JavaScript. Can be passed as a reference variable.
2. Callback with parameters
Naturally, according to past experience, we will think that the callback with parameters looks like the following:
But this won’t work properly. myCallBack(param1, param2) will be executed when this statement is called, not after.
The following syntax is correct:
In this way, the callback function is passed as a function pointer and will be executed after the get operation is completed.