时间:2020-11-14 12:14:11 | 栏目:JavaScript代码 | 点击:次
废话不多说了,直接给大家贴代码了,具体如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var a=0 var test=function(resolve, reject){ setTimeout(function(){ a=4; console.log(a) if(a<2){resolve('200 OK');} if(a>2){reject('400 died');} },3000) } var p1=new Promise(test); p1.then(function(resolve){ console.log(resolve) },function(reject){ console.log(reject); }) </script> </body> </html>
总结