この記事は編集レビューを必要としています。ぜひご協力ください。
この翻訳は不完全です。英語から この記事を翻訳 してください。
これは Harmony(ECMAScript 6) 提案の一部であり、実験段階の技術です。
この技術の仕様は安定していません。ブラウザ互換性の一覧表を確認してください。またこれらの構文や動作は、仕様変更などにより、新しいバージョンのブラウザでは変更される可能性があるという点に注意してください。
概要
引数で与えられた理由でリジェクトされたPromise
オブジェクトを返します。
構文
Promise.reject(reason);
引数
- reason
- この
Promise
オブジェクトのリジェクトされた理由
説明
静的なPromise.reject
関数はリジェクトされたPromise
を返します。デバッグとエラーをキャッチするために、 reason
をinstanceof
Error
するのは役に立ちます。
例
静的なPromise.reject
メソッドを使う
Promise.reject("Testing static reject").then(function(reason) { // not called }, function(reason) { console.log(reason); // "Testing static reject" }); Promise.reject(new Error("fail")).then(function(error) { // not called }, function(error) { console.log(error); // Stacktrace });
仕様
仕様 | 状況 | コメント |
---|---|---|
domenic/promises-unwrapping | Draft | Standardization work is taking place here. |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Promise.reject' in that specification. |
Standard | Initial definition in an ECMA standard. |
ブラウザ実装状況
機能 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
基本サポート | 32 | 24.0 (24.0) as Future 25.0 (25.0) as Promise behind a flag[1]29.0 (29.0) by default |
未サポート | 19 | 7.1 |
機能 | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|
基本サポート | 未サポート | 24.0 (24.0) as Future 25.0 (25.0) as Promise behind a flag[1]29.0 (29.0) by default |
未サポート | 未サポート | iOS 8 | 32 |
[1] Gecko 24では、Promise
をFuture
の初期名称で実験的に実装しています。Gecko 25で最終的な名称にリネームされました。しかし、dom.promise.enabled
フラグによってデフォルトで無効になっています。Bug 918806では、Gecko 29でデフォルトでプロミスを有効にしました。