Comments (1)
Promise相关知识点:
1、 new Promise()
构造函数调用时,传入的函数立即执行,返回 Promise
实例( typeof
结果是 object
),在执行 resolve
或 rejcet
后, then
方法或 catch
方法里的函数,将在当前事件循环结束时被执行。
2、Promise
实例在状态变化后,将不再改变,重复调用 resolve
或 rejcet
都不会再次触发对应的回调函数。但调用这两个函数,并不会停止后面语句的执行。
3、 一个已经改变状态的 promise
函数,仍然可以随时添加对应状态的 then
或 catch
方法,传入的函数将在本轮事件循环结尾执行。
4、 promise
函数内抛出的错误不会反映到外部,有两种情况会发生:
- 错误在调用
resolve
或rejcet
前出现,状态变为rejected
,后面代码不再执行,触发.catch
方法。 - 错误在调用
resolve
或rejcet
后出现,状态正常改变并触发相应的回调,出现的错误被内部吃掉,后面代码不再执行。
5、 then
回调中抛出错误,会被后面的 catch
捕获。
6、 执行 Promise.resolve()
或 Promise.reject()
可立即获得一个 Promise
对象。
from kiinlam.github.io.
Related Issues (19)
- GitHub/Gitlab与SSH密钥的生成、设置
- 支持分享的前端在线代码编辑器(JSFiddle、JS Bin、codepen、codesandbox) HOT 1
- windows本地开发生成证书,nginx配置SSL证书实现https服务
- 一句话解释JavaScript闭包
- [题]函数定义知多少
- VSCode 使用 ESLint 检查 TypeScript
- postMessage API 介绍及其在window.open及iframe中的双向通信应用与示例
- 如何开始一个Web AssemblyScript项目
- 如何克隆github仓库的子目录
- axios请求拦截的奇怪设定
- react及flux架构范例Todomvc分析
- [通知]Blog迁移至Discussions
- nodejs请求转发
- gulp的基础用法
- Git简易教程
- gulp插件
- gulp使用步骤
- gulp工作流
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kiinlam.github.io.