This article mainly introduces the conceptual understanding and usage of javascriptcallback function, and analyzes the function, principle, usage and related aspects of javascript callback function in the form of specific examplesNotes, friends in need can refer to the following
The examples in this article describe the conceptual understanding and usage of javascript callback functions. Share it with everyone for your reference, the details are as follows:
1. The role of the callback function
jsThe code will be executed from the top to the next line , but sometimes we need to wait until one operation is completed before proceeding to the next operation. In this case, we need to use a callback function.
2. Explanation of callback function
Because the function is actually a object, it can be stored in a variable ", pass parameters to another function, create it inside the function, and return the result value from the function", because the function is a built-in object, we can pass it as a parameter to another function, execute it in the function, and even It returns, which has always been regarded as a difficult technology by "professional programmers"
The English explanation of the callback function is:
Translation means: callback function is passed as a variable to another function Function, which is executed after the main function is executed. Function A has a parameter function B, and function B will be called and executed after function A is executed.3. Callback. How to use the function
The code is as follows:function a(callbackFunction){ alert("这是parent函数a"); var m =1; var n=3; return callbackFunction(m,n); } function b(m,n){ alert("这是回调函数B"); return m+n; } $(function(){ var result = a(b); alert("result = "+ result); });
这是parent函数a 这是回调函数B result = 4
.
The above is the detailed content of Conceptual understanding and usage analysis of javascript callback functions. For more information, please follow other related articles on the PHP Chinese website!