promise

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promisepromise

The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.異步

Promise 對象 表明了異步行爲最後的完成(或失敗), 和它的結果值async

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.ide

這篇文章描述了Promise 構造和方法和此類對象的屬性。來了解promise是如何工做的和你如何使用它,我建議先你取讀 Usingpromises
。這個構造是用來簡單的包裝那些並不能徹底支持promise的function ui

 

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]
相關文章
相關標籤/搜索