Promise.reject

Promise.reject

Promise.reject(reason)方法返回一个用reason拒绝的Promise

语法

Promise.reject(reason

参数

reasonPromise被拒绝的原因。

返回值

一个Promise被拒绝的原因。

描述

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

示例

使用静态Promise.reject方法

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

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Promise.reject' in that specification.StandardInitial definition in an ECMA standard.
ECMAScript Latest Draft (ECMA-262)The definition of 'Promise.reject' in that specification.Draft

浏览器兼容性

FeatureChromeFirefoxEdgeInternet ExplorerOperaSafari
Basic Support32.029.0(Yes)(No)197.1

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support4.4.432.0(Yes)29(No)(Yes)8.0