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 (ECMA-262)
Promise.reject
Living Standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
reject()Chrome Full support 32Edge Full support 12Firefox Full support 29IE No support NoOpera Full support 19Safari Full support 8WebView Android Full support 4.4.3Chrome Android Full support 32Firefox Android Full support 29Opera Android Full support 19Safari iOS Full support 8Samsung Internet Android Full support 2.0nodejs Full support 0.12

Legend

Full support  
Full support
No support  
No support

参见