Giter Site home page Giter Site logo

promise's Introduction

promise/A+规范

promise的构造函数可以接受一个带有已成功,已拒绝方法参数的函数,有三种状态,未完成,已成功,已拒绝。promise需要有一个then方法,处理未完成状态到已成功,或者未完成状态到已️拒绝状态的结果,then方法返回一个新的promise可以实现链式调用。

核心**

通过then方法将一系列等待回调函数结果的函数放入数组中,待回调函数又未完成转化为已完成状态时,再将数组中函数依次取出执行,并传入结果。

api

Promise.all(array[promise]);
处理一组promise待该组所有promise执行成功,或者有一个执行失败时返回结果。

Promise.race(array[promise]);
处理一组promise待该组中所任何一个promise执行成功,或者有执行失败时返回结果。

Promise.resolve(arg);
直接执行一个promise无需new一个promise

Promise.reject(arg);
直接执行一个promise无需new一个promise

Promise.delay(ms,arg);
延迟一定时间执行

promise's People

Watchers

7克 avatar  avatar

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.