Javascript custom callback function sample code


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);