<html>
|
<head>
|
<title>Promise</title>
|
<script type='text/javascript'>
|
var ok = true;
|
function successCallBack(){
|
console.log("成功");
|
};
|
function failureCallBack(){
|
console.log("失败");
|
};
|
function successCallBack1(){
|
console.log("成功1");
|
};
|
function failureCallBack1(){
|
console.log("失败1");
|
};
|
|
const wait = ()=> new Promise((resolve,reject)=> {
|
setTimeout(() => {
|
console.log('setTimeout1执行完毕');
|
resolve();
|
}, 0);
|
});
|
|
//调用报错,wait2返回的是setTimeout方法。
|
const wait1 = ()=> setTimeout(() => {
|
console.log('setTimeout2执行完毕');
|
return new Promise((resolve,reject)=> {
|
resolve();
|
});
|
}, 0);
|
|
|
var use = wait().then(successCallBack,failureCallBack).then(successCallBack1,failureCallBack1);
|
</script>
|
</head>
|
<body>
|
|
</body>
|
</html>
|