ES6中的Promise代码详解
作者:m0_37902100 时间:2024-04-18 09:44:19
废话不多说了,直接给大家贴代码了,具体如下所示:
<!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代码详解网站的支持!
来源:http://blog.csdn.net/m0_37902100/article/details/78180235
标签:es6,promise
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何用Python和JS实现的Web SSH工具
2021-04-23 13:50:13
![](https://img.aspxhome.com/file/2023/0/127670_0s.png)
解决Dreamweaver不支持中文文件名方法
2008-01-09 12:52:00
PHP fprintf()函数用法讲解
2023-06-01 20:09:20
![](https://img.aspxhome.com/file/2023/8/55388_0s.png)
JavaScript监听和禁用浏览器回车事件实例
2023-10-12 01:58:16
Web前端应用十种常用技术
2010-09-01 20:46:00
![](https://img.aspxhome.com/file/UploadPic/20109/1/01-96s.jpg)
python os模块在系统管理中的应用
2022-12-17 04:37:23
Python运行报错UnicodeDecodeError的解决方法
2022-03-21 17:21:40
mybatis plus generator 根据数据库自动生成实体类的实现示例
2024-01-25 11:48:00
![](https://img.aspxhome.com/file/2023/3/130903_0s.png)
如何利用insert into values插入多条数据
2024-01-24 04:39:54
Python 文件操作方法总结
2023-11-29 11:36:28
怎么写好一份图形界面设计师简历
2009-04-16 13:10:00
详解django中url路由配置及渲染方式
2021-04-29 01:28:50
![](https://img.aspxhome.com/file/2023/5/77035_0s.png)
python的pytest框架之命令行参数详解(上)
2021-07-23 02:18:07
![](https://img.aspxhome.com/file/2023/9/130579_0s.png)
PHP保留两位小数的几种方法
2023-11-15 05:17:54
python requests.get带header
2022-07-28 20:50:40
![](https://img.aspxhome.com/file/2023/1/97091_0s.jpg)
python3中的类继承你真的了解吗
2021-06-18 11:23:53
一步步解析Python斗牛游戏的概率
2021-05-03 05:17:27
python使用matplotlib画柱状图、散点图
2023-05-18 11:50:06
![](https://img.aspxhome.com/file/2023/7/123797_0s.png)
oracle 树查询 语句
2009-07-17 18:20:00
Blender Python编程实现程序化建模生成超形示例详解
2023-06-14 14:38:53
![](https://img.aspxhome.com/file/2023/8/128518_0s.png)