记录面试中被问到的JS异步编程的方法
回调
function f1(cb) {
setTimeout(() => {
cb && cb();
}, 2000);
}
f1(() => {
console.log("1");
});
promise
f1().then(f2)
记录面试中被问到的JS异步编程的方法
function f1(cb) {
setTimeout(() => {
cb && cb();
}, 2000);
}
f1(() => {
console.log("1");
});
f1().then(f2)