Comments (1)
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)
- node环境下不能打印love
- 发布—订阅模式 HOT 4
- CommonJS规范 HOT 3
- ES6模块
- three.js代码结构
- webpack+react
- three
- 找一个vue或者react技术栈的公司
- virtual dom HOT 1
- diff 算法
- MVVM HOT 2
- git stash || git stash pop HOT 3
- three material HOT 1
- webpack HOT 1
- v-model仅仅是一颗语法糖
- 定义一个const不初始化
- 记一次腾讯面试 HOT 1
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 blog.