JavaScript Promise then()

定义和用法

then() 方法提供两个回调函数:

一个在 Promise 成功时执行,一个在 Promise 被拒绝时执行。

实例

myPromise.then(x => myDisplay(x), x => myDisplay(x));

亲自试一试

语法

promise.then(fulfilled(), rejected())

参数

参数 描述
fulfilled() 当 Promise 成功时要执行的函数。
rejected() 当 Promise 被拒绝时要执行的函数。

返回值

类型 描述
Object 新的 Promise 对象。

浏览器支持

then() 是 ECMAScript 6 (ES6) 的特性。

自 2017 年 6 月以来,ES6 (JavaScript 2015) 在所有现代浏览器中都得到支持:

Chrome Edge Firefox Safari Opera
Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
2016 年 5 月 2017 年 4 月 2017 年 6 月 2016 年 9 月 2016 年 6 月

then() 不支持 Internet Explorer。