Giter Site home page Giter Site logo

认识promise about kiinlam.github.io HOT 1 CLOSED

kiinlam avatar kiinlam commented on September 24, 2024
认识promise

from kiinlam.github.io.

Comments (1)

kiinlam avatar kiinlam commented on September 24, 2024

Promise相关知识点:

1、 new Promise() 构造函数调用时,传入的函数立即执行,返回 Promise 实例( typeof 结果是 object ),在执行 resolverejcet 后, then 方法或 catch 方法里的函数,将在当前事件循环结束时被执行。

2Promise 实例在状态变化后,将不再改变,重复调用 resolverejcet 都不会再次触发对应的回调函数。但调用这两个函数,并不会停止后面语句的执行。

3、 一个已经改变状态的 promise 函数,仍然可以随时添加对应状态的 thencatch 方法,传入的函数将在本轮事件循环结尾执行。

4、 promise 函数内抛出的错误不会反映到外部,有两种情况会发生:

  • 错误在调用 resolverejcet 前出现,状态变为 rejected,后面代码不再执行,触发 .catch 方法。
  • 错误在调用 resolverejcet 后出现,状态正常改变并触发相应的回调,出现的错误被内部吃掉,后面代码不再执行。

5、 then 回调中抛出错误,会被后面的 catch 捕获。

6、 执行 Promise.resolve()Promise.reject() 可立即获得一个 Promise 对象。

from kiinlam.github.io.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.