https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
The Promise
object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.
Promise 对象 代表了异步行为最后的完成(或失败), 和它的结果值
Note: This article describes the Promise
constructor and the methods and properties of such objects. To learn about the way promises work and how you can use them, we advise you to read Using promises first. The constructor is primarily used to wrap functions that do not already support promises.
这篇文章描述了Promise 构造和方法和此类对象的属性。来了解promise是如何工作的和你如何使用它,我建议先你取读 Usingpromises
。这个构造是用来简单的包装那些并不能完全支持promise的function
var promise1 = new Promise(function(resolve, reject) { setTimeout(function() { resolve('foo'); }, 300); }); promise1.then(function(value) { console.log(value); // expected output: "foo" }); console.log(promise1); // expected output: [object Promise]