function runAsync1() {
var p = new Promise(function(resolve, reject) {
//做一些异步操作
try{
//new Array(-1)
resolve('随便什么数据1');
}catch(e){
reject('yichang');
}
});
return p;
}
function runAsync2() {
var p = new Promise(function(resolve, reject) {
//做一些异步操作
resolve('随便什么数据2');
});
return p;
}
runAsync1()
.then(function(data) {
alert(data);
console.log(data);
return runAsync2();
})
.catch(function(reason){
console.log(reason);
})
.then(function(data) {
alert(data);
return '直接返回数据'; //这里直接返回数据
});
ie需下载polyfill.min.js
jquery $.Deferred()
https://www.cnblogs.com/whybxy/p/7645578.html