本文主要和大家分享es6中promise代码实例分析,希望大家更更好掌握promise的用法,感兴趣的朋友参考下吧,希望能帮助到大家。
废话不多说了,直接给大家贴代码了,具体如下所示:
<!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>相关推荐:
以上就是ES6中Promise代码实例分析的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号