talk is cheap ,show me the code
废话少说,放码过来!
第一种:同步回调
//同步回调
function callback(){
console.log("i'm callback function")
}
function main(cb){
console.log("position 1 ");
cb();
console.log("position 2 ");
}
main(callback);
第二种:异步回调
//异步回调
function callback(){
console.log("i'm callback function")
}
function main(cb){
console.log("position 1 ");
setTimeout(cb,1000);
console.log("position 2 ");
}
main(callback);
来源:CSDN
作者:交大彭于晏
链接:https://blog.csdn.net/weixin_42191575/article/details/103592791