Giter Club home page Giter Club logo

Comments (1)

binperson avatar binperson commented on September 22, 2024

Promise 值

function add(xPromise,yPromise) {// Promise.all([ .. ])接受一个promise数组并返回一个新的promise,
// 这个新promise等待数组中的所有promise完成
  return Promise.all( [xPromise, yPromise] )
  // 这个promise决议之后, 我们取得收到的X和Y值并加在一起
    .then( function(values){
// values是来自于之前决议的promisei的消息数组
      return values[0] + values[1];
    } );
}
// fetchX()和fetchY()返回相应值的promise, 可能已经就绪,
// 也可能以后就绪
add( fetchX(), fetchY() )
// 我们得到一个这两个数组的和的promise
// 现在链式调用 then(..)来等待返回promise的决议
  .then( function(sum){
    console.log( sum ); // 这更简单!
  } );

from blog.

Related Issues (18)

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.