Promise.reject() method returns a Promise object that is rejected with a given reason.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

句法

Promise.reject(reason);
					

参数

reason
Reason why this Promise rejected.

返回值

A Promise that is rejected with the given reason.

描述

静态 Promise.reject function returns a Promise that is rejected. For debugging purposes and selective error catching, it is useful to make reason an instanceof Error .

范例

Using the static Promise.reject() method

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

规范

规范
ECMAScript (ECMA-262)
The definition of 'Promise.reject' in that specification.

浏览器兼容性

更新 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 32 Edge 12 Firefox 29 IE No Opera 19 Safari 8 WebView Android 4.4.3 Chrome Android 32 Firefox Android 29 Opera Android 19 Safari iOS 8 Samsung Internet Android 2.0 nodejs 0.12

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: