From 8599f3a62d8ee05080cee1f21d6ec1a20df029a8 Mon Sep 17 00:00:00 2001 From: kangkai <kangk26@foxmail.com> Date: Tue, 30 Mar 2021 18:14:15 +0800 Subject: [PATCH] Promise实例1 --- Promise.html | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/Promise.html b/Promise.html index e69de29..43a81cc 100644 --- a/Promise.html +++ b/Promise.html @@ -0,0 +1,41 @@ +<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> \ No newline at end of file -- Gitblit v1.9.3