<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Promise简单讲解</title>
</head>
<body>
<script>
// 选商品
function selectPro() {
return new Promise(function(res, rej){
setTimeout(function(){
console.log('商品选择好了');
res(['手机','相机'])
}, 3000)
})
}
// 下单
function order() {
return new Promise(function(res, rej){
setTimeout(function(){
// console.log('下单完成');
res(2600);
}, 2000)
})
}
// 收货
function shouhuo() {
return new Promise(function(res, rej) {
setTimeout(function() {
// console.log('收到货了');
res({
name: '张三',
phone: '13988888888'
});
}, 5000)
})
}
selectPro().then((res)=>{
// console.log(res)
return order()
}).then((res)=>{
console.log('付款'+res+'元,下单成功')
return shouhuo()
}).then((res)=>{
console.log(res.name+'收到货了,并且给了好评')
})
</script>
</body>
</html>