Promise.reject()

Promise.reject()方法返回一个带有拒绝原因的Promise对象。

语法

Promise.reject(reason);

参数

reason
表示 Promise被拒绝的原因。

返回值

一个给定原因了的被拒绝的  Promise

描述

静态函数Promise.reject返回一个被拒绝的Promise对象。通过使用Error的实例获取错误原因reason对调试和选择性错误捕捉很有帮助。

示例

使用静态Promise.reject()方法

Promise.reject(new Error('fail')).then(function() {
  // not called
}, function(error) {
  console.error(error); // Stacktrace
});

规范

规范 状态 备注
ECMAScript 2015 (6th Edition, ECMA-262)
Promise.reject
Standard ECMA规范的首次定义
ECMAScript Latest Draft (ECMA-262)
Promise.reject
Draft

浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
reject() Chrome Full support 32 Edge Full support 12 Firefox Full support 29 IE No support No Opera Full support 19 Safari Full support 8 WebView Android Full support 4.4.3 Chrome Android Full support 32 Firefox Android Full support 29 Opera Android Full support Yes Safari iOS Full support 8 Samsung Internet Android Full support 2.0 nodejs Full support 0.12

Legend

Full support  
Full support
No support  
No support

参见