回调函数
用来处理异步问题,例如发送Ajax,setTimeout等
Promise
new Promise((resolve, reject) => {
let resolves = "success";
let errors = "error";
function success() {
setTimeout(function () {
resolve(resolves);//then 的回调
}, 1500)
}
success();
}).then((res) => {
console.log(res); //success
}).catch((error) => {
console.log(error);
})
封装的例子
小程序小程序
网友评论