Javascript custom callback function sample code
- 2020-03-30 04:01:10
- OfStack
If you call it directly from function a, the callback function is limited. But using a function as an argument has the advantage that b becomes a callback function when you have a(b), and you can also have a(c) where c becomes a callback function. If you write functiona(){... ; (b); } loses the flexibility of variables.
function a(index,callback){
callback(index);
}
function b(index){
alert(index);
}
a(10000,b);