基本用法
var p = new Promise(function(resolve, reject) {
setTimeout(function() {
var flag = true;
if(flag) {
resove('hello')
}else {
reject('error')
}
}, 1000)
});
p.then(function(data) {
console.log(data) //hello
},function(info) {
console.log(info) //error
});
::: tip 提示
promise
对象方法all
,race
promise
实例方法.then
,catch
- 可以通过
console.dir(p)
打印查看
:::