let state = 1
function state1(resolve, reject) {
console.log(‘start‘);
if (state == 1) {
resolve(‘start 成功‘)
} else {
reject(‘start 错误‘)
}
}
function state2(resolve, reject) {
console.log(‘next‘);
if (state == 1) {
resolve(‘next 成功‘)
} else {
reject(‘next 错误‘)
}
}
function state3(resolve, reject) {
console.log(‘end‘);
if (state == 1) {
resolve(‘end 成功‘)
} else {
reject(‘end 错误‘)
}
}
new Promise(state1).then(function (val) {
console.log(val); // val是返回值
return new Promise(state2)
}).then(function (val) {
console.log(val); // val是返回值
return new Promise(state3)
}).then(function (val) {
console.log(val); // val是返回值
})