From c01a85c08973313b08dee7932c0d1b46256a1319 Mon Sep 17 00:00:00 2001 From: inokawa <48897392+inokawa@users.noreply.github.com> Date: Wed, 18 Aug 2021 12:42:30 +0900 Subject: Fix typo (#2071) --- .../javascript/reference/global_objects/webassembly/memory/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/memory/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/memory/index.html index 9c93cf21cc..4064df7666 100644 --- a/files/ja/web/javascript/reference/global_objects/webassembly/memory/index.html +++ b/files/ja/web/javascript/reference/global_objects/webassembly/memory/index.html @@ -32,7 +32,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory
Memory.prototype.constructor
このオブジェクトのインスタンスを生成した関数を返します。既定では {{jsxref("WebAssembly.Memory()")}} コンストラクターです。
{{jsxref("WebAssembly/Memory/buffer","Memory.prototype.buffer")}}
-
メモリに格納されているバッファーを返すアクセサープロパティです。/dd>
+
メモリに格納されているバッファーを返すアクセサープロパティです。

インスタンスメソッド

-- cgit v1.2.3-54-g00ecf From 16f49fa325f1784b3b8bac08ada0000e20139291 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Tue, 24 Aug 2021 13:16:40 +0900 Subject: String/substr を更新 (#2093) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown に変換 - 2021/07/21 時点の英語版に同期 --- .../global_objects/string/substr/index.html | 118 --------------------- .../global_objects/string/substr/index.md | 105 ++++++++++++++++++ 2 files changed, 105 insertions(+), 118 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/string/substr/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/string/substr/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/string/substr/index.html b/files/ja/web/javascript/reference/global_objects/string/substr/index.html deleted file mode 100644 index 725bc665df..0000000000 --- a/files/ja/web/javascript/reference/global_objects/string/substr/index.html +++ /dev/null @@ -1,118 +0,0 @@ ---- -title: String.prototype.substr() -slug: Web/JavaScript/Reference/Global_Objects/String/substr -tags: - - Deprecated - - JavaScript - - Method - - Prototype - - Reference - - String - - メソッド -translation_of: Web/JavaScript/Reference/Global_Objects/String/substr ---- -
{{JSRef}}
- -

substr() メソッドは、文字列の一部を、指定した位置から後方向指定した文字数だけ返します。

- -
{{EmbedInteractiveExample("pages/js/string-substr.html")}}
- - - -

構文

- -
str.substr(start[, length])
- -

引数

- -
-
start
-
返却する部分文字列に含まれる最初の文字の位置です。
-
length
-
任意です。取り出す文字の数です。
-
- -

返値

- -

指定された文字列の指定された部分が入った新しい文字列です。

- -

解説

- -

substr() は、 str のうち length 文字分を、 start の位置から数えて抽出します。

- - - -

ポリフィル

- -

Microsoft の JScript は start の位置として負の数に対応していません。この機能を使用したい場合は、このバグを回避するために、次の互換コードを使用することができます。

- -
// only run when the substr() function is broken
-if ('ab'.substr(-1) != 'b') {
-  /**
-   *  Get the substring of a string
-   *  @param  {integer}  start   where to start the substring
-   *  @param  {integer}  length  how many characters to return
-   *  @return {string}
-   */
-  String.prototype.substr = function(substr) {
-    return function(start, length) {
-      // call the original method
-      return substr.call(this,
-      	// did we get a negative start, calculate how much it is from the beginning of the string
-        // adjust the start parameter for negative value
-        start < 0 ? this.length + start : start,
-        length)
-    }
-  }(String.prototype.substr);
-}
-
- -

- -

substr() の使用

- -
var aString = 'Mozilla';
-
-console.log(aString.substr(0, 1));   // 'M'
-console.log(aString.substr(1, 0));   // ''
-console.log(aString.substr(-1, 1));  // 'a'
-console.log(aString.substr(1, -1));  // ''
-console.log(aString.substr(-3));     // 'lla'
-console.log(aString.substr(1));      // 'ozilla'
-console.log(aString.substr(-20, 2)); // 'Mo'
-console.log(aString.substr(20, 2));  // ''
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-string.prototype.substr', 'String.prototype.substr')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.String.substr")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/string/substr/index.md b/files/ja/web/javascript/reference/global_objects/string/substr/index.md new file mode 100644 index 0000000000..a7d7dcc40f --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/string/substr/index.md @@ -0,0 +1,105 @@ +--- +title: String.prototype.substr() +slug: Web/JavaScript/Reference/Global_Objects/String/substr +tags: + - Deprecated + - JavaScript + - Method + - Prototype + - Reference + - String + - メソッド +browser-compat: javascript.builtins.String.substr +translation_of: Web/JavaScript/Reference/Global_Objects/String/substr +--- +{{JSRef}} + +**`substr()`** メソッドは、文字列の一部を、指定した位置から後方向に指定した文字数だけ返します。 + +{{EmbedInteractiveExample("pages/js/string-substr.html")}} + +## 構文 + +```js +substr(start) +substr(start, length) +``` + +### 引数 + +- `start` + - : 返却する部分文字列に含まれる最初の文字の位置です。 +- `length` + - : オプションです。取り出す文字の数です。 + +### 返値 + +指定された文字列の指定された部分が入った新しい文字列です。 + +## 解説 + +`substr()` は、 `str` のうち `start` の位置から `length` 文字分を数えて抽出します。 + +- `start` が正の数である場合、文字列の先頭から数えた位置になります。この値は `str.length` が上限になります。 +- `start` が負の数である場合、文字列の末尾から数えた位置になります。この値は `-str.length` が下限になります。 +- メモ: Microsoft の JScript では、 `start` の引数が負の数であっても文字列の末尾からの位置にはなりません。 +- `length` が省略された場合、 `substr()` は文字列の末尾までの文字を抽出します。 +- `length` が {{jsxref("undefined")}} である場合、 `substr()` は文字列の末尾までの文字を抽出します。 +- `length` が負の数である場合、 `0` として扱われます。 +- `start` および `length` において、 {{jsxref("NaN")}} は `0` として扱われます。 + +## ポリフィル + +Microsoft の JScript は start の位置として負の数に対応していません。この機能を JScript で使用する場合は、以下のコードを使用することができます。 + +```js +// only run when the substr() function is broken +if ('ab'.substr(-1) != 'b') { + /** + * Get the substring of a string + * @param {integer} start where to start the substring + * @param {integer} length how many characters to return + * @return {string} + */ + String.prototype.substr = function(substr) { + return function(start, length) { + // call the original method + return substr.call(this, + // did we get a negative start, calculate how much it is from the beginning of the string + // adjust the start parameter for negative value + start < 0 ? this.length + start : start, + length) + } + }(String.prototype.substr); +} +``` + +## 例 + +### substr() の使用 + +```js +var aString = 'Mozilla'; + +console.log(aString.substr(0, 1)); // 'M' +console.log(aString.substr(1, 0)); // '' +console.log(aString.substr(-1, 1)); // 'a' +console.log(aString.substr(1, -1)); // '' +console.log(aString.substr(-3)); // 'lla' +console.log(aString.substr(1)); // 'ozilla' +console.log(aString.substr(-20, 2)); // 'Mo' +console.log(aString.substr(20, 2)); // '' +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("String.prototype.slice()")}} +- {{jsxref("String.prototype.substring()")}} -- cgit v1.2.3-54-g00ecf From ceaac49d854e31a1ffc0f0ce929de408b801337b Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Thu, 26 Aug 2021 01:30:46 +0900 Subject: WeakMap/clear を更新 (#2113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown に変換 - 2021/07/21 時点の英語版に同期 --- .../global_objects/weakmap/clear/index.html | 51 --------------------- .../global_objects/weakmap/clear/index.md | 53 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 51 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/weakmap/clear/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/weakmap/clear/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/weakmap/clear/index.html b/files/ja/web/javascript/reference/global_objects/weakmap/clear/index.html deleted file mode 100644 index b538566db1..0000000000 --- a/files/ja/web/javascript/reference/global_objects/weakmap/clear/index.html +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: WeakMap.prototype.clear() -slug: Web/JavaScript/Reference/Global_Objects/WeakMap/clear -tags: - - JavaScript - - Method - - Obsolete - - Prototype - - WeakMap -translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/clear ---- -
{{JSRef}} {{obsolete_header}}
- -

clear() メソッドは、WeakMap オブジェクトからすべての要素を削除するために使用されていましたが、もはや ECMAScript とその実装に含まれていません。

- -

構文

- -
wm.clear();
- -

- -

clear メソッドを使う

- -
var wm = new WeakMap();
-var obj = {};
-
-wm.set(obj, "foo");
-wm.set(window, "bar");
-
-wm.has(obj); // true
-wm.has(window); // true
-
-wm.clear();
-
-wm.has(obj)  // false
-wm.has(window)  // false
-
- -

仕様

- -

すべての現在の仕様やドラフトでサポートされていません。このメソッドは、リビジョン 28 (October 14, 2014 のバージョン)まで ECMAScript 第 6 版ドラフトでサポートされていました。しかし、最新バージョンのドラフトで削除されました。最終仕様では、サポートされていません。

- -

ブラウザ実装状況

- -

{{Compat("javascript.builtins.WeakMap.clear")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/weakmap/clear/index.md b/files/ja/web/javascript/reference/global_objects/weakmap/clear/index.md new file mode 100644 index 0000000000..18f7ab622b --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/weakmap/clear/index.md @@ -0,0 +1,53 @@ +--- +title: WeakMap.prototype.clear() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/clear +tags: + - JavaScript + - Method + - Deprecated + - Prototype + - WeakMap +browser-compat: javascript.builtins.WeakMap.clear +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/clear +--- +{{JSRef}} {{deprecated_header}} + +**`clear()`** メソッドは、 `WeakMap` オブジェクトからすべての要素を削除するために使用されていましたが、もはや ECMAScript とその実装に含まれていません。 + +## 構文 + +```js +clear() +``` + +## 例 + +### `clear` メソッドの使用 + +```js example-bad +var wm = new WeakMap(); +var obj = {}; + +wm.set(obj, 'foo'); +wm.set(window, 'bar'); + +wm.has(obj); // true +wm.has(window); // true + +wm.clear(); + +wm.has(obj) // false +wm.has(window) // false +``` + +## 仕様書 + +どの標準にも含まれていません。 + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("WeakMap")}} -- cgit v1.2.3-54-g00ecf From ce37d8bfd5b7aef8a088babfa2bc2ff63c79ed21 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Thu, 26 Aug 2021 01:31:01 +0900 Subject: JavaScript の RegExp/lastIndex を更新 (#2114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - RegExp/lastIndex を Markdown 化し、2021/08/17 時点の英語版に同期 - RegExp/hasIndices を新規翻訳 --- .../global_objects/regexp/hasindices/index.md | 70 +++++++++++++++++ .../global_objects/regexp/lastindex/index.html | 87 ---------------------- .../global_objects/regexp/lastindex/index.md | 74 ++++++++++++++++++ 3 files changed, 144 insertions(+), 87 deletions(-) create mode 100644 files/ja/web/javascript/reference/global_objects/regexp/hasindices/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/regexp/hasindices/index.md b/files/ja/web/javascript/reference/global_objects/regexp/hasindices/index.md new file mode 100644 index 0000000000..6b8788a480 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/regexp/hasindices/index.md @@ -0,0 +1,70 @@ +--- +title: RegExp.prototype.hasIndices +slug: Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices +tags: + - Draft + - JavaScript + - Property + - Prototype + - Reference + - RegExp + - Regular Expressions +browser-compat: javascript.builtins.RegExp.hasIndices +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices +--- +{{JSRef}} + +**`hasIndices`** プロパティは、その正規表現で "`d`" フラグが使用されたかどうかを示します。 `hasIndices` はそれぞれの正規表現インスタンスの読み取り専用プロパティです。 + +{{EmbedInteractiveExample("pages/js/regexp-prototype-hasindices.html")}} + +{{JS_Property_Attributes(0, 0, 1)}} + +## 解説 + +`hasIndices` の値は論理型であり、 "`d`" フラグが使用された場合は `true` になります。それ以外の場合は `false` になります。 "`d`" フラグは正規表現による一致の結果に、各キャプチャグループの部分文字列の開始と終了の位置を含めることを示します。 + +このプロパティを直接変更することはできません。 + +## 例 + +### `hasIndices` の使用 + +```js +const str1 = 'foo bar foo'; + +const regex1 = new RegExp('foo', 'gd'); + +console.log(regex1.hasIndices); // 出力: true + +console.log(regex1.exec(str1).indices[0]); // 出力: Array [0, 3] +console.log(regex1.exec(str1).indices[0]); // 出力: Array [8, 11] + +const str2 = 'foo bar foo'; + +const regex2 = new RegExp('foo'); + +console.log(regex2.hasIndices); // 出力: false + +console.log(regex2.exec(str2).indices); // 出力: undefined +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{JSxRef("RegExp.lastIndex")}} +- {{JSxRef("RegExp.prototype.exec()")}} +- {{JSxRef("RegExp.prototype.dotAll")}} +- {{JSxRef("RegExp.prototype.global")}} +- {{JSxRef("RegExp.prototype.ignoreCase")}} +- {{JSxRef("RegExp.prototype.multiline")}} +- {{JSxRef("RegExp.prototype.source")}} +- {{JSxRef("RegExp.prototype.sticky")}} +- {{JSxRef("RegExp.prototype.unicode")}} diff --git a/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html b/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html deleted file mode 100644 index ce94abd766..0000000000 --- a/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.html +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: RegExp.lastIndex -slug: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex -tags: - - JavaScript - - Property - - Reference - - RegExp - - Regular Expression -translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex ---- -
{{JSRef}}
- -

lastIndex は正規表現インスタンスの読み書き可能なプロパティで、次の一致を開始する位置を指定します。

- -
{{EmbedInteractiveExample("pages/js/regexp-lastindex.html")}}
- -
{{js_property_attributes(1, 0, 0)}}
- -

構文

- -
regExpObj.lastIndex
- -

解説

- -

このプロパティは、正規表現インスタンスがグローバル検索を示すために g フラグを使用した場合、または粘着的検索を示すために y フラグを使用した場合にのみ設定されます。以下の規則が適用されます。

- -
    -
  • lastIndex が文字列の長さよりも大きければ、 {{jsxref("RegExp.prototype.test()", "test()")}} および {{jsxref("RegExp.prototype.exec()", "exec()")}} は失敗し、lastIndex は 0 にセットされます。
  • -
  • lastIndex が文字列の長さ以下で、かつ正規表現が空文字列に一致する場合には、正規表現は lastIndex から始まる入力に一致します。
  • -
  • lastIndex が文字列の長さと等しく、かつ、正規表現が空文字列に一致しない場合、正規表現は入力に一致せず、 lastIndex は 0 にリセットされます。
  • -
  • それ以外の場合は、 lastIndex は直近の一致に続く次の位置に設定されます。
  • -
- -

- -

lastIndex の使用

- -

例えば、以下の連続した処理を考えてみてください。:

- -
var re = /(hi)?/g;
-
- -

空文字列に一致します。

- -
console.log(re.exec('hi'));
-console.log(re.lastIndex);
-
- -

lastIndex が 2 になり["hi", "hi"] が返ります。

- -
console.log(re.exec('hi'));
-console.log(re.lastIndex);
-
- -

ゼロ番目の要素が一致した文字列なので、 ["", undefined] という空配列が返ります。この場合、 lastIndex が 2 であったときに (そして 2 のままである)、 hi の長さが 2 であるので、空文字列になります。

- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-properties-of-regexp-instances', 'RegExp.lastIndex')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.RegExp.lastIndex")}}

-
- -

関連情報

- -
    -
  • {{jsxref("RegExp.prototype.ignoreCase")}}
  • -
  • {{jsxref("RegExp.prototype.global")}}
  • -
  • {{jsxref("RegExp.prototype.multiline")}}
  • -
  • {{jsxref("RegExp.prototype.source")}}
  • -
  • {{jsxref("RegExp.prototype.sticky")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.md b/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.md new file mode 100644 index 0000000000..5416149a87 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/regexp/lastindex/index.md @@ -0,0 +1,74 @@ +--- +title: 'RegExp: lastIndex' +slug: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex +tags: + - JavaScript + - Property + - Reference + - RegExp + - 正規表現 +browser-compat: javascript.builtins.RegExp.lastIndex +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex +--- +{{JSRef}} + +**`lastIndex`** は {{jsXref("RegExp")}} インスタンスの読み書き可能なプロパティで、次の一致を開始する位置を指定します。 + +なお、 `lastIndex` は {{jsXref("RegExp")}} プロトタイプのプロパティではありませんが、 {{jsXref("RegExp")}} インスタンスからのみ公開されます。 + +{{EmbedInteractiveExample("pages/js/regexp-lastindex.html")}}{{js_property_attributes(1, 0, 0)}} + +## 解説 + +このプロパティは、正規表現インスタンスがグローバル検索を示すために `g` フラグを使用した場合、または粘着的検索を示すために `y` フラグを使用した場合にのみ設定されます。 {{jsxref("RegExp.prototype.test()", "test()")}} および {{jsxref("RegExp.prototype.exec()", "exec()")}} が指定された入力に対して呼び出されたとき、以下の規則が適用されます。 + +- `lastIndex` が入力の長さよりも大きい場合、 `exec()` または `test()` は一致するものを見つけられず、 `lastIndex` は 0 に設定されます。 +- `lastIndex` が入力の長さ以下であった場合、 `exec()` または `test()` は `lastIndex` から一致するものを探そうとします。 + + - `exec()` または `test()` が一致するものを見つけた場合 `lastIndex` は入力の中の一致する文字列の末尾の位置に設定されます。 + - `exec()` または `test()` が一致するものを見つけられなかった場合、 `lastIndex` は 0 に設定されます。 + +## 例 + +### lastIndex の使用 + +例えば、以下の一連の処理を考えてみてください。 + +```js +var re = /(hi)?/g; +``` + +空文字列に一致します。 + +```js +console.log(re.exec('hi')); +console.log(re.lastIndex); +``` + +`["hi", "hi"]` を返し、 `lastIndex` は 2 になります。 + +```js +console.log(re.exec('hi')); +console.log(re.lastIndex); +``` + +返値は `["", undefined]` で、 0 番目の要素が一致文字列となる空の配列です。この場合、 `lastIndex` が 2 (現在も 2) であり、`hi` の長さが 2 であるため、空の文字列となります。 + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{JSxRef("RegExp.prototype.dotAll")}} +- {{JSxRef("RegExp.prototype.global")}} +- {{JSxRef("RegExp.prototype.hasIndices")}} +- {{JSxRef("RegExp.prototype.ignoreCase")}} +- {{JSxRef("RegExp.prototype.multiline")}} +- {{JSxRef("RegExp.prototype.source")}} +- {{JSxRef("RegExp.prototype.sticky")}} +- {{JSxRef("RegExp.prototype.unicode")}} -- cgit v1.2.3-54-g00ecf From e784f81665d6d497f98487403d76cc8020943ee0 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Fri, 27 Aug 2021 00:02:37 +0900 Subject: Global_Objects/Promise/allSettled を更新 (#2234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global_objects/promise/allsettled/index.html | 92 -------------------- .../global_objects/promise/allsettled/index.md | 99 ++++++++++++++++++++++ 2 files changed, 99 insertions(+), 92 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/promise/allsettled/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/promise/allsettled/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/promise/allsettled/index.html b/files/ja/web/javascript/reference/global_objects/promise/allsettled/index.html deleted file mode 100644 index 117abc02c9..0000000000 --- a/files/ja/web/javascript/reference/global_objects/promise/allsettled/index.html +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: Promise.allSettled() -slug: Web/JavaScript/Reference/Global_Objects/Promise/allSettled -tags: - - JavaScript - - Method - - Promise - - Reference - - allSettled - - asynchronous - - プロミス - - メソッド - - 非同期 -translation_of: Web/JavaScript/Reference/Global_Objects/Promise/allSettled ---- -
{{JSRef}}
- -

Promise.allSettled() メソッドは、与えられたすべてのプロミスが満足したか拒否された後に、それぞれのプロミスの結果を記述した配列オブジェクトで解決されるプロミスを返します。

- -

一般的には、複数の非同期タスクがあり、お互いに依存せずに正常に完了する場合や、各プロミスの結果を常に知りたい場合に使用されます。

- -

これと比較して、 {{jsxref("Promise.all()")}} で返されるプロミスは、タスクがお互いに依存している場合や、タスクのいずれかが拒否されたときにすぐに拒否したい場合にはより適切かもしれません。

- -
{{EmbedInteractiveExample("pages/js/promise-allsettled.html")}}
- -

構文

- -
Promise.allSettled(iterable);
- -

引数

- -
-
iterable
-
{{jsxref("Array")}} などの反復可能オブジェクトで、それぞれの要素が Promise であるものです。
-
- -

返値

- -

待ち状態の {{jsxref("Promise")}} で、指定されたプロミスの集合に含まれるすべてのプロミスが、正常に解決されるか拒否されるかのどちらかで完了すると、非同期に解決されます。その際、返されたプロミスのハンドラーには、元のプロミスの集合に含まれるの各プロミスの結果を含む配列が入力として渡されます。

- -

ただし、空の反復可能オブジェクトが引数として渡された場合に限りPromise.allSettled() は空の配列として解決済みの Promise オブジェクトを返します。

- -

出力されるそれぞれのオブジェクトには、 status の文字列が存在します。 status が fulfilled であれば、 value が存在します。 status が rejected であれば、 reason が存在します。 value (または reason) はそれぞれのプロミスがどの値で解決 (または拒否) されたかを反映します。

- -

- -

Promise.allSettled の使用

- -
Promise.allSettled([
-  Promise.resolve(33),
-  new Promise(resolve => setTimeout(() => resolve(66), 0)),
-  99,
-  Promise.reject(new Error('an error'))
-])
-.then(values => console.log(values));
-
-// [
-//   {status: "fulfilled", value: 33},
-//   {status: "fulfilled", value: 66},
-//   {status: "fulfilled", value: 99},
-//   {status: "rejected",  reason: Error: an error}
-// ]
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-promise.allsettled', 'Promise.allSettled')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.Promise.allSettled")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/promise/allsettled/index.md b/files/ja/web/javascript/reference/global_objects/promise/allsettled/index.md new file mode 100644 index 0000000000..e96b5fe08e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/promise/allsettled/index.md @@ -0,0 +1,99 @@ +--- +title: Promise.allSettled() +slug: Web/JavaScript/Reference/Global_Objects/Promise/allSettled +tags: + - JavaScript + - メソッド + - プロミス + - Reference + - allSettled + - 非同期 + - Polyfill +browser-compat: javascript.builtins.Promise.allSettled +translation_of: Web/JavaScript/Reference/Global_Objects/Promise/allSettled +--- +{{JSRef}} + +**`Promise.allSettled()`** メソッドは、与えられたすべてのプロミスが履行されたか拒否された後に、それぞれのプロミスの結果を記述した配列オブジェクトで解決されるプロミスを返します。 + +一般的には、複数の非同期タスクがあり、お互いに依存せずに正常に完了する場合や、各プロミスの結果を常に知りたい場合に使用されます。 + +これに対して、 {{jsxref("Promise.all()")}} で返されるプロミスは、タスクがお互いに依存している場合や、タスクのいずれかが拒否されたときにすぐに拒否したい場合にはより適切かもしれません。 + +{{EmbedInteractiveExample("pages/js/promise-allsettled.html")}} + +## 構文 + +```js +Promise.allSettled(iterable); +``` + +### 引数 + +- `iterable` + - : {{jsxref("Array")}} などの[反復可能](/ja/docs/Web/JavaScript/Reference/Iteration_protocols)オブジェクトで、それぞれの要素が `Promise` であるものです。 + +### 返値 + +**待ち状態**の {{jsxref("Promise")}} で、指定されたプロミスの集合に含まれるすべてのプロミスが、正常に履行されるか拒否されるかのどちらかで完了すると、**非同期に**解決されます。その際、返されたプロミスのハンドラーには、元のプロミスの集合に含まれるの各プロミスの結果を含む配列が入力として渡されます。 + +ただし、空の反復可能オブジェクトが引数として渡された**場合に限り**、 `Promise.allSettled()` は空の配列として**解決済みの** `Promise` オブジェクトを返します。 + +出力されるそれぞれのオブジェクトには、 `status` の文字列が存在します。 status が `fulfilled` (履行) であれば、 `value` が存在します。 status が `rejected` (拒否) であれば、 `reason` が存在します。 value (または reason) はそれぞれのプロミスがどの値で履行 (または拒否) されたかを反映します。 + +## 例 + +### Promise.allSettled の使用 + +#### {{JSxRef("Promise.then", "Promise.prototype.then()")}} +```js +Promise.allSettled([ + Promise.resolve(33), + new Promise(resolve => setTimeout(() => resolve(66), 0)), + 99, + Promise.reject(new Error('an error')) +]) +.then(values => console.log(values)); + +// [ +// {status: "fulfilled", value: 33}, +// {status: "fulfilled", value: 66}, +// {status: "fulfilled", value: 99}, +// {status: "rejected", reason: Error: an error} +// ] +``` + +#### {{jsxref("Operators/await", "await")}} +```js +const values = await Promise.allSettled([ + Promise.resolve(33), + new Promise(resolve => setTimeout(() => resolve(66), 0)), + 99, + Promise.reject(new Error('an error')) +]) +console.log(values) + +// [ +// {status: "fulfilled", value: 33}, +// {status: "fulfilled", value: 66}, +// {status: "fulfilled", value: 99}, +// {status: "rejected", reason: Error: an error} +// ] +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- `Promise.allSettled` のポリフィルが [`core-js`](https://github.com/zloirock/core-js#ecmascript-promise) で利用できます +- [Promises](/ja/docs/Archive/Add-ons/Techniques/Promises) +- [プロミスの使用](/ja/docs/Web/JavaScript/Guide/Using_promises) +- [プロミスを使った行儀のよい非同期のプログラミング](/ja/docs/Learn/JavaScript/Asynchronous/Promises) +- {{jsxref("Promise")}} +- {{jsxref("Promise.all()")}} -- cgit v1.2.3-54-g00ecf From 0c0907b0e5c8f261e03b4a6f3de1fb73c4689de7 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Fri, 27 Aug 2021 20:34:24 +0900 Subject: Intl.DateTimeFormat オブジェクトを更新 (#2143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Intl.DateTimeFormat オブジェクトを更新 Intl.DateTimeFormat オブジェクト、 DateTimeFormat() コンストラクターを 2021/08/20 時点の英語版に更新 * Intl.DateTimeFormat.format を更新 * Intl.DateTimeFormat.formatToParts を更新 * Intl.DateTimeFormat.formatRange を更新 * Intl.DateTimeFormat.formatRangeToParts を更新 * Intl.DateTimeFormat.resolvedOptions を更新 * Intl.DateTimeFormat.supportedLocalesOf を更新 --- .../intl/datetimeformat/datetimeformat/index.html | 233 ------------------ .../intl/datetimeformat/datetimeformat/index.md | 261 +++++++++++++++++++++ .../intl/datetimeformat/format/index.html | 111 --------- .../intl/datetimeformat/format/index.md | 101 ++++++++ .../intl/datetimeformat/formatrange/index.html | 88 ------- .../intl/datetimeformat/formatrange/index.md | 81 +++++++ .../datetimeformat/formatrangetoparts/index.html | 81 ------- .../datetimeformat/formatrangetoparts/index.md | 78 ++++++ .../intl/datetimeformat/formattoparts/index.html | 239 ------------------- .../intl/datetimeformat/formattoparts/index.md | 238 +++++++++++++++++++ .../global_objects/intl/datetimeformat/index.html | 182 -------------- .../global_objects/intl/datetimeformat/index.md | 179 ++++++++++++++ .../intl/datetimeformat/resolvedoptions/index.html | 93 -------- .../intl/datetimeformat/resolvedoptions/index.md | 75 ++++++ .../datetimeformat/supportedlocalesof/index.html | 83 ------- .../datetimeformat/supportedlocalesof/index.md | 71 ++++++ 16 files changed, 1084 insertions(+), 1110 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html deleted file mode 100644 index 7a98ab57cf..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.html +++ /dev/null @@ -1,233 +0,0 @@ ---- -title: Intl.DateTimeFormat() コンストラクター -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat -tags: - - Constructor - - DateTimeFormat - - Intl - - JavaScript - - Reference - - コンストラクター -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat ---- -
{{JSRef}}
- -

Intl.DateTimeFormat() コンストラクターは、言語に応じた日付と時刻の書式化を可能にするオブジェクトのためのものです。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html")}}
- - - -

構文

- -
new Intl.DateTimeFormat([locales[, options]])
- -

引数

- -
-
locales {{optional_inline}}
-
-

BCP47 言語タグの文字列、または、そのような文字列の配列です。ブラウザーの既定のロケールを使用するには、空の配列を渡してください。。 Unicode 拡張に対応しています (例えば "en-US-u-ca-buddhist" など)。 locales 引数の一般的な形式と解釈は、 {{jsxref("Global_Objects/Intl", "Intl", "#Locale_identification_and_negotiation", 1)}} のページをご覧ください。次の Unicode 拡張キーが利用できます。

- -
-
nu
-
番号方式。使用できる値は次のとおりです。 "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt"
-
ca
-
カレンダー。使用できる値は次のとおりです。 "buddhist", "chinese", "coptic", "ethiopia", "ethiopic", "gregory", "hebrew", "indian", "islamic", "iso8601", "japanese", "persian", "roc"
-
hc
-
時制。使用できる値は次の通りです。 "h11", "h12", "h23", "h24".
-
-
-
options {{optional_inline}}
-
-

以下のプロパティの一部またはすべてを持つオブジェクトです。

- -
-
dateStyle
-
format() が呼び出された際に使用される日付の書式化スタイルです。利用可能な値は以下のとおりです。 -
    -
  • "full"
  • -
  • "long"
  • -
  • "medium"
  • -
  • "short"
  • -
- -
-

dateStyletimeStyle と一緒に使用することができますが、他のオプションと一緒に使用することができません (例えば weekday, hour, month, など)。

-
-
-
timeStyle
-
format() が呼び出された際に使用される時刻の書式化スタイルです。利用可能な値は以下のとおりです。 -
    -
  • "full"
  • -
  • "long"
  • -
  • "medium"
  • -
  • "short"
  • -
-
-
-
-

timeStyledateStyle と一緒に使用することができますが、他のオプションと一緒に使用することができません (例えば weekday, hour, month, など)。

-
-
-
calendar
-
暦です。有効な値は、 "buddhist", "chinese", " coptic", "ethiopia", "ethiopic", "gregory", " hebrew", "indian", "islamic", "iso8601", " japanese", "persian", "roc" です。
-
dayPeriod
-
日単位の期間の表現の仕方です。有効な値は、 "narrow", "short", " long" です。
-
numberingSystem
-
命数法です。有効な値は、 "arab", "arabext", " bali", "beng", "deva", "fullwide", " gujr", "guru", "hanidec", "khmr", " knda", "laoo", "latn", "limb", "mlym", " mong", "mymr", "orya", "tamldec", " telu", "thai", "tibt" です。
-
localeMatcher
-
使用するロケール一致アルゴリズム。利用可能な値は "lookup" と "best fit" です。既定値は "best fit" です。このオプションについての詳細は、 {{jsxref("Global_Objects/Intl", "Intl のページ", "#Locale_negotiation", 1)}}をご覧ください。
-
timeZone
-
使用するタイムゾーン。実装が認識しなければならない唯一の値は "UTC" です。既定値は、実行時の既定のタイムゾーンです。実装は、 IANA タイムゾーンデータベースのタイムゾーン名、例えば "Asia/Shanghai", "Asia/Kolkata", "America/New_York" なども認識できる場合があります。
-
hour12
-
12時制を使用するかどうか (24時制に対して)。可能な値は truefalse です。既定ではロケールに依存します。このオプションは hc 言語タグや hourCycle オプションと一緒に使用された場合、これらを上書きします。
-
hourCycle
-
使用する時の周期です。利用可能な値は "h11", "h12", "h23", "h24" です。このオプションは hc 言語タグと一緒に使用された場合はそれを上書きし、両方のオプションが指定されていた場合は hour12 オプションが優先されます。
-
formatMatcher
-
使用する書式一致アルゴリズム。可能な値は "basic" と "best fit" です。既定値は "best fit" です。このプロパティの使用方法については、以下の項を参照してください。
-
- -

以下のプロパティは、書式化の出力や、要求された表現で使用する日付や時刻のコンポーネントです。実装は、少なくとも以下のサブセットに対応することが要求されています。

- -
    -
  • weekday, year, month, day, hour, minute, second
  • -
  • weekday, year, month, day
  • -
  • year, month, day
  • -
  • year, month
  • -
  • month, day
  • -
  • hour, minute, second
  • -
  • hour, minute
  • -
- -

実装は他のサブセットに対応することもでき、要求はすべての利用可能な表現の中から最適なものを見つけるために交渉します。 formatMatcher プロパティによるこの交渉や選択には2つのアルゴリズムが利用できます。完全に定義された "basic" アルゴリズムと、実装に依存した"best fit" アルゴリズムです。

- -
-
weekday
-
曜日の表現です。利用可能な値は以下の通りです。 -
    -
  • "long" (例 Thursday)
  • -
  • "short" (例 Thu)
  • -
  • "narrow" (例 T)。ロケールによっては、 narrow 形式が同じ曜日が2つある場合もあります (例 Tuesday の narrow 形式も T です)。
  • -
-
-
era
-
時代の表現です。利用可能な値は以下の通りです。 -
    -
  • "long" (例 Anno Domini, 紀元)
  • -
  • "short" (例 AD)
  • -
  • "narrow" (例 A)
  • -
-
-
year
-
年の表現です。利用可能な値は以下の通りです。 -
    -
  • "numeric" (例 2012)
  • -
  • "2-digit" (例 12)
  • -
-
-
month
-
月の表現です。利用可能な値は以下の通りです。 -
    -
  • "numeric" (例 2)
  • -
  • "2-digit" (例 02)
  • -
  • "long" (例 March)
  • -
  • "short" (例 Mar)
  • -
  • "narrow" (例 M)。ロケールによっては、 narrow 形式が同じ月が2つある場合もあります (例 May の narrow 形式も M です)。
  • -
-
-
day
-
日の表現です。利用可能な値は以下の通りです。 -
    -
  • "numeric" (例 1)
  • -
  • "2-digit" (例 01)
  • -
-
-
hour
-
時の表現です。利用可能な値は "numeric", "2-digit" です。
-
minute
-
分の表現です。利用可能な値は "numeric", "2-digit" です。
-
second
-
秒の表現です。利用可能な値は "numeric", "2-digit" です。
-
fractionalSecondDigits
-
-
-

Firefox 84, Chrome 84, などで追加されました。詳しくは互換性一覧表を参照してください。

-
- 秒の小数点以下を表すために使用される数字の桁数 (その先の桁は切り捨てられます)。利用可能な値は次の通りです。 - -
    -
  • 0 (小数点以下は切り捨て)
  • -
  • 1 (小数点以下は1桁で表される。例えば、 736 は 7 と書式化される。)
  • -
  • 2 (小数点以下は2桁で表される。例えば、 736 は 73 と書式化される。)
  • -
  • 3 (小数点以下は2桁で表される。例えば、 736 は 736 と書式化される。)
  • -
-
-
timeZoneName
-
タイムゾーン名の表現です。利用可能な値は以下の通りです。 -
    -
  • "long" (例 British Summer Time)
  • -
  • "short" (例 GMT+1)
  • -
-
-
- -

日付・時間コンポーネントプロパティの既定値は {{jsxref("undefined")}} ですが、すべてのコンポーネントプロパティが {{jsxref("undefined")}} であった場合、 year, month, day は "numeric" であると仮定されます。

-
-
- -

- -

DateTimeFormat の使用

- -

ロケールを指定しない基本的な使用方法では、 DateTimeFormat は既定のロケールとオプションを使用します。

- -
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
-
-// toLocaleString without arguments depends on the implementation,
-// the default locale, and the default time zone
-console.log(new Intl.DateTimeFormat().format(date));
-// → "12/19/2012" if run with en-US locale (language) and time zone America/Los_Angeles (UTC-0800)
- -

timeStyle と dateStyle の使用

- -
let o = new Intl.DateTimeFormat("en" , {
-  timeStyle: "short"
-});
-console.log(o.format(Date.now())); // "13:31 AM"
-
-let o = new Intl.DateTimeFormat("en" , {
-  dateStyle: "short"
-});
-console.log(o.format(Date.now())); // "07/07/20"
-
-let o = new Intl.DateTimeFormat("en" , {
-  timeStyle: "medium",
-  dateStyle: "short"
-});
-console.log(o.format(Date.now())); // "07/07/20, 13:31:55 AM"
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-intl-datetimeformat-constructor', 'Intl.DateTimeFormat')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.Intl.DateTimeFormat.DateTimeFormat")}}

- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.md new file mode 100644 index 0000000000..9dd69a4d94 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/datetimeformat/index.md @@ -0,0 +1,261 @@ +--- +title: Intl.DateTimeFormat() コンストラクター +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat +tags: + - Constructor + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.DateTimeFormat +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat +--- +{{JSRef}} + +**`Intl.DateTimeFormat()`** コンストラクターは、言語に応じた日付と時刻の書式化を可能にする +{{jsxref("Intl/DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトを生成します。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html", "taller")}} + + +## 構文 + +```js +new Intl.DateTimeFormat() +new Intl.DateTimeFormat(locales) +new Intl.DateTimeFormat(locales, options) +``` + +### 引数 + +- `locales` {{optional_inline}} + - : BCP 47 言語タグの文字列、または、そのような文字列の配列です。ブラウザーの既定のロケールを使用するには、空の配列を渡してください。。 Unicode 拡張に対応しています (例えば "`en-US-u-ca-buddhist`" など)。 `locales` 引数の一般的な形式と解釈は、 {{jsxref("Global_Objects/Intl", "Intl", "#Locale_identification_and_negotiation", 1)}} のページをご覧ください。次の Unicode 拡張キーが利用できます。 + + - `nu` + - : 番号方式。使用できる値は "`arab`", "`arabext`", "`bali`", "`beng`", "`deva`", "`fullwide`", "`gujr`", "`guru`", "`hanidec`", "`khmr`", "`knda`", "`laoo`", "`latn`", "`limb`", "`mlym`", "`mong`", "`mymr`", "`orya`", "`tamldec`", "`telu`", "`thai`", "`tibt`" です。 + - `ca` + - : カレンダー。使用できる値は "`buddhist`", "`chinese`", "`coptic`", "`ethiopia`", "`ethiopic`", "`gregory`", "`hebrew`", "`indian`", "`islamic`", "`iso8601`", "`japanese`", "`persian`", "`roc`" です。 + - `hc` + - : 時制。使用できる値は "`h11`", "`h12`", "`h23`", "`h24`" です。 + +- `options` {{optional_inline}} + + - : 以下のプロパティの一部またはすべてを持つオブジェクトです。 + + - `dateStyle` + + - : `format()` が呼び出された際に使用される日付の書式化スタイルです。利用可能な値は以下のとおりです。 + - "`full`" + - "`long`" + - "`medium`" + - "`short`" + + > **Note:** `dateStyle` は `timeStyle` と一緒に使用することができますが、他のオプション (`weekday`, `hour`, `month`, など) と一緒に使用することはできません。 + + - `timeStyle` + - : `format()` が呼び出された際に使用される時刻の書式化スタイルです。利用可能な値は以下のとおりです。 + + - "`full`" + - "`long`" + - "`medium`" + - "`short`" + + > **Note:** `timeStyle` は `dateStyle` と一緒に使用することができますが、他のオプション (`weekday`, `hour`, `month`, など) と一緒に使用することはできません。 + - `calendar` + - : 暦です。有効な値は、 "`buddhist`", "`chinese`", " `coptic`", "`ethiopia`", "`ethiopic`", "`gregory`", " `hebrew`", "`indian`", "`islamic`", "`iso8601`", " `japanese`", "`persian`", "`roc`" です。 + - `dayPeriod` + + - : 日単位の期間の表現の仕方です。有効な値は、 "`narrow`", "`short`", " `long`" です。 + + > **Note:** + > + > - このオプションは12時間制を使用したときのみ効果があります。 + > - 多くのロケールでは幅の指定を無視して同じ文字列を使用します。 + + - `numberingSystem` + - : 命数法です。有効な値は、 "`arab`", "`arabext`", " `bali`", "`beng`", "`deva`", "`fullwide`", " `gujr`", "`guru`", "`hanidec`", "`khmr`", " `knda`", "`laoo`", "`latn`", "`limb`", "`mlym`", " `mong`", "`mymr`", "`orya`", "`tamldec`", " `telu`", "`thai`", "`tibt`" です。 + - `localeMatcher` + - : 使用するロケール一致アルゴリズム。利用可能な値は "`lookup`" と "`best fit`" です。既定値は "`best fit`" です。このオプションについての詳細は、 {{jsxref("Global_Objects/Intl", "Intl", "#Locale_negotiation", 1)}} のページをご覧ください。 + - `timeZone` + - : 使用するタイムゾーン。実装が認識しなければならない唯一の値は "`UTC`" です。既定値は、実行時の既定のタイムゾーンです。実装は、 [IANA タイムゾーンデータベース](https://www.iana.org/time-zones)のタイムゾーン名、例えば "`Asia/Shanghai`", "`Asia/Kolkata`", "`America/New_York`" なども認識できる場合があります。 + - `hour12` + - : (24 時制に対して) 12 時制を使用するかどうか。可能な値は `true` と `false` です。既定ではロケールに依存します。このオプションは `hc` 言語タグや `hourCycle` オプションと一緒に使用された場合、これらを上書きします。 + - `hourCycle` + - : 使用する時の周期です。利用可能な値は "`h11`", "`h12`", "`h23`", "`h24`" です。このオプションは `hc` 言語タグと一緒に使用された場合はそれを上書きし、両方のオプションが指定されていた場合は `hour12` オプションが優先されます。 + - `formatMatcher` + - : 使用する書式一致アルゴリズム。可能な値は "`basic`" と "`best fit`" です。既定値は "`best fit`" です。このプロパティの使用方法については、以下の項を参照してください。 + + 以下のプロパティは、書式化の出力や、要求された表現で使用する日付や時刻のコンポーネントです。実装は、少なくとも以下のサブセットに対応することが要求されています。 + + - `weekday`, `year`, `month`, `day`, `hour`, `minute`, `second` + - `weekday`, `year`, `month`, `day` + - `year`, `month`, `day` + - `year`, `month` + - `month`, `day` + - `hour`, `minute`, `second` + - `hour`, `minute` + + 実装は他のサブセットに対応することもでき、要求はすべての利用可能な表現の中から最適なものを見つけるために交渉します。 `formatMatcher` プロパティによるこの交渉や選択には2つのアルゴリズムが利用できます。[完全に定義された "`basic`" アルゴリズム](https://www.ecma-international.org/ecma-402/1.0/#BasicFormatMatcher)と、実装に依存した "`best fit`" アルゴリズムです。 + + - `weekday` + + - : 曜日の表現です。利用可能な値は以下の通りです。 + - "`long`" (例 `Thursday`) + - "`short`" (例 `Thu`) + - "`narrow`" (例 `T`)。ロケールによっては、 narrow 形式が同じ曜日が2つある場合もあります (例 `Tuesday` の narrow 形式も `T` です)。 + + - `era` + + - : 時代の表現です。利用可能な値は以下の通りです。 + + - "`long`" (例 `Anno Domini`, 紀元) + - "`short`" (例 `AD`) + - "`narrow`" (例 `A`) + + - `year` + + - : 年の表現です。利用可能な値は以下の通りです。 + + - "`numeric`" (例 `2012`) + - "`2-digit`" (例 `12`) + + - `month` + + - : 月の表現です。利用可能な値は以下の通りです。 + - "`numeric`" (例 `2`) + - "`2-digit`" (例 `02`) + - "`long`" (例 `March`) + - "`short`" (例 `Mar`) + - "`narrow`" (例 `M`)。ロケールによっては、 narrow 形式が同じ月が2つある場合もあります (例 `May` の narrow 形式も `M` です)。 + + - `day` + + - : 日の表現です。利用可能な値は以下の通りです。 + + - "`numeric`" (例 `1`) + - "`2-digit`" (例 `01`) + + - `hour` + - : 時の表現です。利用可能な値は "`numeric`", "`2-digit`" です。 + - `minute` + - : 分の表現です。利用可能な値は "`numeric`", "`2-digit`" です。 + - `second` + - : 秒の表現です。利用可能な値は "`numeric`", "`2-digit`" です。 + - `fractionalSecondDigits` + - : 秒の小数点以下を表すために使用される数字の桁数 (その先の桁は切り捨てられます)。利用可能な値は次の通りです。 + + - `0` (小数点以下は切り捨て) + - `1` (小数点以下は1桁で表される。例えば、 736 は `7` と書式化される。) + - `2` (小数点以下は2桁で表される。例えば、 736 は `73` と書式化される。) + - `3` (小数点以下は2桁で表される。例えば、 736 は `736` と書式化される。) + + - `timeZoneName` + + - : タイムゾーン名の表現です。利用可能な値は以下の通りです。 + + - "`long`" ローカライズされた長い形式 (例 `Pacific Standard Time`, `Nordamerikanische Westküsten-Normalzeit`) + - "`short`" ローカライズされた短い形式 (例 `PST`, `GMT-8`) + - "`shortOffset`" ローカライズされた短い GMT 形式 (例 `GMT-8`) + - "`longOffset`" ローカライズされた長い GMT 形式 (例 `GMT-0800`) + - "`shortGeneric`" 一般的な場所を指定しない短い形式 (例 `PT`, `Los Angeles Zeit`). + - "`longGeneric`" 一般的な場所を指定しない長い形式 (例 `Pacific Time`, `Nordamerikanische Westküstenzeit`) + + > **Note:** タイムゾーンの表示は、必要な文字列が利用できない場合、別の形式にフォールバックすることがあります。例えば、場所を指定しない形式では、 "Pacific Time" のように特定の国や都市の場所を指定せずにタイムゾーンを表示する必要がありますが、 "Los Angeles Time" のようなタイムゾーンにフォールバックする場合があります。 + + それぞれの日付や時刻の部分のプロパティの既定値は {{jsxref("undefined")}} ですが、すべての部分のプロパティが {{jsxref("undefined")}} であった場合、 `year`, `month`, `day` は "`numeric`" であると想定されます。 + +## 例 + +### DateTimeFormat の使用 + +ロケールを指定しない基本的な使用方法では、 `DateTimeFormat` は既定のロケールとオプションを使用します。 + +```js +let date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); + +// toLocaleString without arguments depends on the implementation, +// the default locale, and the default time zone +console.log(new Intl.DateTimeFormat().format(date)); +// → "12/19/2012" if run with en-US locale (language) and time zone America/Los_Angeles (UTC-0800) +``` + +### timeStyle と dateStyle の使用 + +```js +let o = new Intl.DateTimeFormat("en" , { + timeStyle: "short" +}); +console.log(o.format(Date.now())); // "13:31 AM" + +let o = new Intl.DateTimeFormat("en" , { + dateStyle: "short" +}); +console.log(o.format(Date.now())); // "07/07/20" + +let o = new Intl.DateTimeFormat("en" , { + timeStyle: "medium", + dateStyle: "short" +}); +console.log(o.format(Date.now())); // "07/07/20, 13:31:55 AM" +``` + +### dayPeriod の使用 + +`dayPeriod` オプションを使用して、1日の時間帯 (「朝」、「夜」、「正午」など) を表す文字列を出力します。なお、これは 12 時間制の書式でのみ有効であり、 (`hourCycle: 'h12'`)、多くのロケールでは `dayPeriod` の値に関係なく同じ文字列が出力されます。 + +```js +let date = Date.UTC(2012, 11, 17, 4, 0, 42); + +console.log(new Intl.DateTimeFormat('en-GB', { hour: 'numeric', hourCycle: 'h12', +dayPeriod: 'short', timeZone: 'UTC' }).format(date)); +// > 4 at night" (same formatting in en-GB for all dayPeriod values) + +console.log(new Intl.DateTimeFormat('fr', { hour: 'numeric', hourCycle: 'h12', + dayPeriod: 'narrow', timeZone: 'UTC' }).format(date)); +// > "4 mat." (same output in French for both narrow/short dayPeriod) + +console.log(new Intl.DateTimeFormat('fr', { hour: 'numeric', hourCycle: 'h12', + dayPeriod: 'long', timeZone: 'UTC' }).format(date)); +// > "4 du matin" +``` + +### timeZoneName の使用 + +`timeZoneName` を使用して、タイムゾーンの文字列 ("GMT", "Pacific Time", など) を出力します。 + +```js +var date = Date.UTC(2021, 11, 17, 3, 0, 42); +const timezoneNames = ['short', 'long', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric'] + +for (const zoneName of timezoneNames) { + // Do something with currentValue + var formatter = new Intl.DateTimeFormat('en-US', { + timeZone: 'America/Los_Angeles', + timeZoneName: zoneName, + }); + console.log(zoneName + ": " + formatter.format(date) ); +} + +// expected output: +// > "short: 12/16/2021, PST" +// > "long: 12/16/2021, Pacific Standard Time" +// > "shortOffset: 12/16/2021, GMT-8" +// > "longOffset: 12/16/2021, GMT-08:00" +// > "shortGeneric: 12/16/2021, PT" +// > "longGeneric: 12/16/2021, Pacific Time" +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.DateTimeFormat")}} +- {{jsxref("Global_Objects/Intl", "Intl")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html deleted file mode 100644 index a7606b00f0..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.html +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: Intl.DateTimeFormat.prototype.format() -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format -tags: - - DateTimeFormat - - Internationalization - - Intl - - JavaScript - - Method - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format ---- -
{{JSRef}}
- -

Intl.NumberFormat.prototype.format() メソッドは、この {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトのロケールと整形オプションに従って日付や時刻を整形します。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-format.html", "taller")}}
- - - -

構文

- -
dateTimeFormat.format(date)
- -

引数

- -
-
date
-
整形する日付や時刻です。
-
- -

解説

- -

format ゲッター関数は、この {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトのロケールと整形オプションに従って日付や時刻を整形し、文字列に格納します。

- -

- -

format の使用

- -

format ゲッター関数を使用して単一の日付値を整形します。こちらはセルビアの例です。

- -
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
-var dateTimeFormat = new Intl.DateTimeFormat('sr-RS', options);
-console.log(dateTimeFormat.format(new Date()));
-// → "недеља, 7. април 2013."
-
- -

format と map の使用

- -

format ゲッター関数を使用して、配列内のすべての日付を整形することができます。なお、この関数は供給元である {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map()")}} に渡すことができます。

- -
var a = [new Date(2012, 08), new Date(2012, 11), new Date(2012, 03)];
-var options = { year: 'numeric', month: 'long' };
-var dateTimeFormat = new Intl.DateTimeFormat('pt-BR', options);
-var formatted = a.map(dateTimeFormat.format);
-console.log(formatted.join('; '));
-// → "setembro de 2012; dezembro de 2012; abril de 2012"
-
- -

書式化された日付値を固定値と比較することは避ける

- -

ほとんどの場合、 format() が返す書式は一貫しています。しかし、これは将来的に変更される可能性があり、すべての言語で保証されているわけではありません — 出力のバリエーションは設計上のものであり、仕様上は許容されています。最も注目すべきは、 IE や Edge ブラウザは日付の周りに双方向の制御文字を挿入するため、他のテキストと連結したときに出力テキストが適切に流れることです。

- -

このことから、 format() の結果と固定値を比較することができると期待してはいけません。

- -
let d = new Date("2019-01-01T00:00:00.000000Z");
-let formattedDate = Intl.DateTimeFormat(undefined, {
-  year: 'numeric',
-  month: 'numeric',
-  day: 'numeric',
-  hour: 'numeric',
-  minute: 'numeric',
-  second: 'numeric'
-}).format(d);
-
-"1.1.2019, 01:00:00" === formattedDate;
-// true in Firefox and others
-// false in IE and Edge
-
- -
-

: この StackOverflow のスレッドに詳細や例があります。

-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-intl.datetimeformat.prototype.format', 'Intl.DateTimeFormat.format')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.Intl.DateTimeFormat.format")}}

- -

関連情報

- -
    -
  • {{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}
  • -
  • {{jsxref("Date.prototype.toLocaleString()")}}
  • -
  • {{jsxref("Date.prototype.toLocaleDateString()")}}
  • -
  • {{jsxref("Date.prototype.toLocaleTimeString()")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.md new file mode 100644 index 0000000000..2cd8c9fae8 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/format/index.md @@ -0,0 +1,101 @@ +--- +title: Intl.DateTimeFormat.prototype.format() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.format +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format +--- +{{JSRef}} + +The **`Intl.DateTimeFormat.prototype.format()`** メソッドは、この {{jsxref("Intl.DateTimeFormat")}} オブジェクトのロケールと整形オプションに従って日付や時刻を整形します。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-format.html", "taller")}} + + +## 構文 + +```js +format(date) +``` + +### 引数 + +- `date` + - : 整形する日付です。 + +## 解説 + +`format` ゲッター関数は、この {{jsxref("Intl/DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトのロケールと整形オプションに従って日付や時刻を整形し、文字列に格納します。 + +## 例 + +### format の使用 + +`format` ゲッター関数を使用して単一の日付値を整形します。こちらはセルビアの例です。 + +```js +var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; +var dateTimeFormat = new Intl.DateTimeFormat('sr-RS', options); +console.log(dateTimeFormat.format(new Date())); +// → "недеља, 7. април 2013." +``` + +### format と map の使用 + +`format` ゲッター関数を使用して、配列内のすべての日付を整形することができます。なお、この関数は供給元である {{jsxref("Intl/DateTimeFormat", "Intl.DateTimeFormat")}} に結び付けられているので、直接 {{jsxref("Array.prototype.map()")}} に渡すことができます。 + +```js +var a = [new Date(2012, 08), new Date(2012, 11), new Date(2012, 03)]; +var options = { year: 'numeric', month: 'long' }; +var dateTimeFormat = new Intl.DateTimeFormat('pt-BR', options); +var formatted = a.map(dateTimeFormat.format); +console.log(formatted.join('; ')); +// → "setembro de 2012; dezembro de 2012; abril de 2012" +``` + +### 書式化された日付値を固定値と比較することは避ける + +ほとんどの場合、 `format()` が返す書式は一貫しています。しかし、これは将来的に変更される可能性があり、すべての言語で保証されているわけではありません — 出力のバリエーションは設計上のものであり、仕様上は許容されています。最も注目すべきは、 IE や Edge ブラウザは日付の周りに双方向の制御文字を挿入するため、他のテキストと連結したときに出力テキストが適切に流れることです。 + +このことから、 `format()` の結果と固定値を比較することができると期待してはいけません。 + +```js example-bad +let d = new Date("2019-01-01T00:00:00.000000Z"); +let formattedDate = Intl.DateTimeFormat(undefined, { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric' +}).format(d); + +"1.1.2019, 01:00:00" === formattedDate; +// true in Firefox and others +// false in IE and Edge +``` + +> **Note:** この [StackOverflow のスレッド](https://stackoverflow.com/questions/25574963/ies-tolocalestring-has-strange-characters-in-results)に詳細や例があります。 + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.DateTimeFormat")}} +- {{jsxref("Date.prototype.toLocaleString()")}} +- {{jsxref("Date.prototype.toLocaleDateString()")}} +- {{jsxref("Date.prototype.toLocaleTimeString()")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html deleted file mode 100644 index 1722354d9e..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.html +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: Intl.DateTimeFormat.prototype.formatRange() -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange -tags: - - JavaScript - - Method - - Reference - - メソッド -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange ---- -
{{JSRef}}
- -

Intl.DateTimeFormat.prototype.formatRange() は、日付の範囲をもっとも簡明な方法で、 {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトがインスタンス化されたときに提供された localeoptions に基づいて書式化します。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-formatrange.html", "taller")}}
- - - -

構文

- -
Intl.DateTimeFormat.prototype.formatRange(startDate, endDate)
- -

- -

基本的な formatRange の使用

- -

このメソッドは2つの {{jsxref("Date")}} を受け取り、 {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトがインスタンス化されたときに提供された localeoptions に基づいて日付の範囲を書式化します。

- -
let date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0));
-let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0));
-let date3 = new Date(Date.UTC(2007, 0, 20, 10, 0, 0));
-// > 'Wed, 10 Jan 2007 10:00:00 GMT'
-// > 'Wed, 10 Jan 2007 11:00:00 GMT'
-// > 'Sat, 20 Jan 2007 10:00:00 GMT'
-
-let fmt1 = new Intl.DateTimeFormat("en", {
-    year: '2-digit',
-    month: 'numeric',
-    day: 'numeric',
-    hour: 'numeric',
-    minute: 'numeric'
-});
-console.log(fmt1.format(date1));
-console.log(fmt1.formatRange(date1, date2));
-console.log(fmt1.formatRange(date1, date3));
-// > '1/10/07, 10:00 AM'
-// > '1/10/07, 10:00 – 11:00 AM'
-// > '1/10/07, 10:00 AM – 1/20/07, 10:00 AM'
-
-let fmt2 = new Intl.DateTimeFormat("en", {
-    year: 'numeric',
-    month: 'short',
-    day: 'numeric'
-});
-console.log(fmt2.format(date1));
-console.log(fmt2.formatRange(date1, date2));
-console.log(fmt2.formatRange(date1, date3));
-// > 'Jan 10, 2007'
-// > 'Jan 10, 2007'
-// > 'Jan 10 – 20, 2007'
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('Intl.DateTimeFormat.formatRange', '#sec-intl.datetimeformat.prototype.formatRange', 'formatRange()')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.DateTimeFormat.formatRange")}}

-
- -

関連情報

- -
    -
  • {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md new file mode 100644 index 0000000000..0c14478615 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md @@ -0,0 +1,81 @@ +--- +title: Intl.DateTimeFormat.prototype.formatRange() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.formatRange +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange +--- +{{JSRef}} + +**`Intl.DateTimeFormat.prototype.formatRange()`** は、 {{jsxref("Intl.DateTimeFormat")}} オブジェクトがインスタンス化されたときに提供された **`locale`** と **`options`** に基づいて、もっとも簡明な方法で日付の範囲を書式化します。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-formatrange.html", + "taller")}} + + +## 構文 + +```js +formatRange(startDate, endDate) +``` + +## 例 + +### 基本的な formatRange の使用 + +このメソッドは 2 つの {{jsxref("Date")}} を受け取り、 {{jsxref("Intl/DateTimeFormat", "Intl.DateTimeFormat")}} オブジェクトがインスタンス化されたときに提供された `locale` と `options` に基づいて日付の範囲を書式化します。 + +```js +let date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0)); +let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0)); +let date3 = new Date(Date.UTC(2007, 0, 20, 10, 0, 0)); +// > 'Wed, 10 Jan 2007 10:00:00 GMT' +// > 'Wed, 10 Jan 2007 11:00:00 GMT' +// > 'Sat, 20 Jan 2007 10:00:00 GMT' + +let fmt1 = new Intl.DateTimeFormat("en", { + year: '2-digit', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric' +}); +console.log(fmt1.format(date1)); +console.log(fmt1.formatRange(date1, date2)); +console.log(fmt1.formatRange(date1, date3)); +// > '1/10/07, 10:00 AM' +// > '1/10/07, 10:00 – 11:00 AM' +// > '1/10/07, 10:00 AM – 1/20/07, 10:00 AM' + +let fmt2 = new Intl.DateTimeFormat("en", { + year: 'numeric', + month: 'short', + day: 'numeric' +}); +console.log(fmt2.format(date1)); +console.log(fmt2.formatRange(date1, date2)); +console.log(fmt2.formatRange(date1, date3)); +// > 'Jan 10, 2007' +// > 'Jan 10, 2007' +// > 'Jan 10 – 20, 2007' +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.DateTimeFormat")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html deleted file mode 100644 index be4d8a0bc4..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.html +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: Intl.DateTimeFormat.prototype.formatRangeToParts() -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts -tags: - - Internationalization - - JavaScript - - Localization - - Method - - Reference - - i18n -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts ---- -

{{JSRef}}

- -

Intl.DateTimeFormat.prototype.formatRangeToParts() メソッドは、 DateTimeFormat フォーマッターで生成される期間の各部品を表すロケール特有のトークンを提供します。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-formatrangetoparts.html", "taller")}}
- - - -

構文

- -
Intl.DateTimeFormat.prototype.formatRangeToParts(startDate, endDate)
- -

- -

基本的な formatRangeToParts の使い方

- -

このメソッドは2つの {{jsxref("Date")}} を受け取り、期間を書式化する際の各部品を表すロケール特有のトークンを含む {{jsxref("Array")}} オブジェクトを返します。

- -
let date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0));
-let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0));
-// > 'Wed, 10 Jan 2007 10:00:00 GMT'
-// > 'Wed, 10 Jan 2007 11:00:00 GMT'
-
-let fmt = new Intl.DateTimeFormat("en", {
-    hour: 'numeric',
-    minute: 'numeric'
-});
-
-console.log(fmt.formatRange(date1, date2));
-// > '10:00 – 11:00 AM'
-
-fmt.formatRangeToParts(date1, date2);
-// return value:
-// [
-//   { type: 'hour',      value: '10',  source: "startRange" },
-//   { type: 'literal',   value: ':',   source: "startRange" },
-//   { type: 'minute',    value: '00',  source: "startRange" },
-//   { type: 'literal',   value: ' – ', source: "shared"     },
-//   { type: 'hour',      value: '11',  source: "endRange"   },
-//   { type: 'literal',   value: ':',   source: "endRange"   },
-//   { type: 'minute',    value: '00',  source: "endRange"   },
-//   { type: 'literal',   value: ' ',   source: "shared"     },
-//   { type: 'dayPeriod', value: 'AM',  source: "shared"     }
-// ]
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('Intl.DateTimeFormat.formatRange', '#sec-Intl.DateTimeFormat.prototype.formatRangeToParts', 'formatRangeToParts()')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.Intl.DateTimeFormat.formatRangeToParts")}}

- -

関連情報

- -
    -
  • {{jsxref("Intl.DateTimeFormat.prototype.formatRange()")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md new file mode 100644 index 0000000000..034909ed3c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md @@ -0,0 +1,78 @@ +--- +title: Intl.DateTimeFormat.prototype.formatRangeToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.formatRangeToParts +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts +--- +{{JSRef}} + +**`Intl.DateTimeFormat.prototype.formatRangeToParts()`** メソッドは、 {{jsxref("Intl.DateTimeFormat")}} フォーマッターで生成される期間の各部品を表すロケール特有のトークンを提供します。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-formatrangetoparts.html", + "taller")}} + + +## 構文 + +```js +formatRangeToParts(startDate, endDate) +``` + +## 例 + +### 基本的な formatRangeToParts の使い方 + +このメソッドは2つの {{jsxref("Date")}} を受け取り、期間を書式化する際の各部品を表す*ロケール特有*のトークンを含む {{jsxref("Array")}} オブジェクトを返します。 + +> **Note:** 返値は現在のロケールで表示されるので、以下のものとは異なる可能性があります。 + +```js +let date1 = new Date(Date.UTC(2007, 0, 10, 10, 0, 0)); +let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0)); +// > 'Wed, 10 Jan 2007 10:00:00 GMT' +// > 'Wed, 10 Jan 2007 11:00:00 GMT' + +let fmt = new Intl.DateTimeFormat("en", { + hour: 'numeric', + minute: 'numeric' +}); + +console.log(fmt.formatRange(date1, date2)); +// > '10:00 – 11:00 AM' + +fmt.formatRangeToParts(date1, date2); +// return value: +// [ +// { type: 'hour', value: '10', source: "startRange" }, +// { type: 'literal', value: ':', source: "startRange" }, +// { type: 'minute', value: '00', source: "startRange" }, +// { type: 'literal', value: ' – ', source: "shared" }, +// { type: 'hour', value: '11', source: "endRange" }, +// { type: 'literal', value: ':', source: "endRange" }, +// { type: 'minute', value: '00', source: "endRange" }, +// { type: 'literal', value: ' ', source: "shared" }, +// { type: 'dayPeriod', value: 'AM', source: "shared" } +// ] +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl/DateTimeFormat/formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}} +- {{jsxref("Intl.DateTimeFormat")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html deleted file mode 100644 index 04e140d0e8..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.html +++ /dev/null @@ -1,239 +0,0 @@ ---- -title: DateTimeFormat.prototype.formatToParts() -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts -tags: - - DateTimeFormat - - Internationalization - - Intl - - JavaScript - - Method - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts ---- -
{{JSRef}}
- -

Intl.DateTimeFormat.prototype.formatToParts() メソッドは、ロケールを意識した DateTimeFormat フォーマッターが生成する文字列のロケールを考慮した書式化を可能にします。

- -

構文

- -
dateTimeFormat.formatToParts(date)
- -

引数

- -
-
date {{optional_inline}}
-
書式化する日付。
-
- -

返値

- -

書式化された日付のパーツを含むオブジェクトの {{jsxref("Array")}} です。

- -

解説

- -

formatToParts() メソッドは、日付文字列のフォーマットをカスタマイズするときに役立ちます。これは、ロケール特有の部分を保持しながら、カスタム文字列を構築できるロケール特有のトークンを含むオブジェクトの {{jsxref("Array")}} を返します。formatToParts() メソッドが返却する構造は、このようになります。

- -
[
-  { type: 'day', value: '17' },
-  { type: 'weekday', value: 'Monday' }
-]
- -

渡される可能性がある type は以下のとおりです。

- -
-
day
-
日付として使用される文字列。たとえば、 "17"。
-
dayPeriod
-
日付期間として使用される文字列。たとえば、 "AM", "PM", "in the morning", "noon" など。
-
era
-
時代として使用される文字列。たとえば、"BC" や "AD"。
-
fractionalSecond
-
小数点以下の秒として使用される文字列です。例えば "0" や "00" や "000" です。
-
hour
-
時刻として使用される文字列。たとえば "3" や "03"。
-
literal
-
日付や時刻の区切りとして使用される文字列。たとえば "/"、","、"o'clock"、"de"。
-
minute
-
分として使用される文字列。たとえば、"00"。
-
month
-
月として使用される文字列。たとえば、"12"。
-
relatedYear
-
カレンダーの表現が year ではなくyearNameである場合、関連する4桁のグレゴリオ暦の年に使用される文字列です。例えば "2019" です。
-
second
-
秒として使用される文字列。たとえば、"07" や "42"。
-
timeZoneName
-
タイムゾーン名として使用される文字列。たとえば、"UTC"。
-
weekday
-
曜日として使用される文字列。たとえば、"M" や "Monday"、"Montag"。
-
year
-
年として使用される文字列。たとえば、"2012" や "96"。
-
yearName
-
関連するコンテキストで yearName に使用される文字列、例えば "geng-zi" など。
-
- -

ポリフィル

- -

この機能のポリフィルは、提案リポジトリから利用できます。

- -

- -

DateTimeFormat は、直接操作できないローカライズされた透過的でない文字列を出力します。

- -
var date = Date.UTC(2012, 11, 17, 3, 0, 42);
-
-var formatter = new Intl.DateTimeFormat('en-us', {
-  weekday: 'long',
-  year: 'numeric',
-  month: 'numeric',
-  day: 'numeric',
-  hour: 'numeric',
-  minute: 'numeric',
-  second: 'numeric',
-  fractionalSecondDigits: 3,
-  hour12: true,
-  timeZone: 'UTC'
-});
-
-formatter.format(date);
-// "Monday, 12/17/2012, 3:00:42.000 AM"
-
- -

しかし、多くのユーザーインターフェイスでは、この文字列の書式をカスタマイズしたいという要望があります。 formatToParts メソッドは、文字列を部品単位で提供することで、 DateTimeFormat フォーマッターによって生成された文字列のロケールを意識した書式設定ができるようになります。

- -
formatter.formatToParts(date);
-
-// return value:
-[
-  { type: 'weekday',   value: 'Monday' },
-  { type: 'literal',   value: ', '     },
-  { type: 'month',     value: '12'     },
-  { type: 'literal',   value: '/'      },
-  { type: 'day',       value: '17'     },
-  { type: 'literal',   value: '/'      },
-  { type: 'year',      value: '2012'   },
-  { type: 'literal',   value: ', '     },
-  { type: 'hour',      value: '3'      },
-  { type: 'literal',   value: ':'      },
-  { type: 'minute',    value: '00'     },
-  { type: 'literal',   value: ':'      },
-  { type: 'second',    value: '42'     },
-  { type: 'fractionalSecond', value: '000' },
-  { type: 'literal',   value: ' '      },
-  { type: 'dayPeriod', value: 'AM'     }
-]
-
- -

これで情報は個別に利用可能になり、カスタマイズされた方法で再び書式化して連結することができます。例えば、{{jsxref("Array.prototype.map()")}}、アロー関数switch 文テンプレートリテラル、 {{jsxref("Array.prototype.reduce()")}} などを使用しています。

- -
var dateString = formatter.formatToParts(date).map(({type, value}) => {
-  switch (type) {
-    case 'dayPeriod': return `<b>${value}</b>`;
-    default : return value;
-  }
-}).reduce((string, part) => string + part);
-
- -

これにより、 formatToParts() メソッドを使用する際に、日の部分が太字になります。

- -
console.log(formatter.format(date));
-// "Monday, 12/17/2012, 3:00:42.000 AM"
-
-console.log(dateString);
-// "Monday, 12/17/2012, 3:00:42.000 <b>AM</b>"
- -

名前付きの年と混合カレンダー

- -

いくつかのケースでは、暦は名前付きの年を使用しています。 例えば、中国やチベットの暦では、60年周期の干支を使用しています。これらの年は、グレゴリオ暦の年と関連付けて識別されます。このような場合、 formatToParts() の結果は、通常は年が存在するはずなのに、年の項目ではなく、4桁のグレゴリオ暦の年を含む relatedYear のエントリを含むことになります。バッグの中の項目を (任意の値で) year に設定すると、年と yearName グレゴリオ暦の relatedYear の両方が得られます。

- -
let opts = { year: "numeric", month: "numeric", day: "numeric" };
-let df = new Intl.DateTimeFormat("zh-u-ca-chinese", opts);
-df.formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42));
-
-// return value
-[
-  { type: 'relatedYear', value: '2012' },
-  { type: 'literal', value: '年' },
-  { type: 'month', value: '十一月' },
-  { type: 'day', value: '4' }
-]
-
- -

year オプションがバッグ内で設定されていない場合 (任意の値に設定されている場合)、結果には relatedYear のみが含まれます。

- -
let df = new Intl.DateTimeFormat("zh-u-ca-chinese");
-df.formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42));
-
-// 返値
-[
-   { type: 'relatedYear', value: '2012' },
-   { type: 'literal', value: '年' },
-   { type: 'month', value: '十一月' },
-   { type: 'day', value: '4' }
-]
-
- -

year を出力したい場合は、 .format() は一般的にこれらを並べて表示することができます。

- -
let df = new Intl.DateTimeFormat("zh-u-ca-chinese", {year: "numeric"});
-df.format(Date.UTC(2012, 11, 17, 3, 0, 42));
-
-// 返値
-2012壬辰年
- -

これにより、ロケールとカレンダーを両方の format で混在させることも可能になります。

- -
let df = new Intl.DateTimeFormat("en-u-ca-chinese", {year: "numeric"});
-let date = Date.UTC(2012, 11, 17, 3, 0, 42);
-df.format(date);
-
-// 返値
-2012(ren-chen)
-
- -

および formatToParts の場合

- -
let opts = {month: 'numeric', day: 'numeric', year: "numeric"};
-let df = new Intl.DateTimeFormat("en-u-ca-chinese", opts);
-let date = Date.UTC(2012, 11, 17, 3);
-df.formatToParts(date)
-
-// 返値
-[
-  { type: 'month', value: '11' },
-  { type: 'literal', value: '/' },
-  { type: 'day', value: '4' },
-  { type: 'literal', value: '/' },
-  { type: 'relatedYear', value: '2012' }
-]
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-Intl.DateTimeFormat.prototype.formatToParts', 'Intl.DateTimeFormat.prototype.formatToParts')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.DateTimeFormat.formatToParts")}}

-
- -

関連情報

- -
    -
  • {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}
  • -
  • {{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format")}}
  • -
  • {{jsxref("Date.prototype.toLocaleString()")}}
  • -
  • {{jsxref("Date.prototype.toLocaleDateString()")}}
  • -
  • {{jsxref("Date.prototype.toLocaleTimeString()")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md new file mode 100644 index 0000000000..cbe6256671 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md @@ -0,0 +1,238 @@ +--- +title: Intl.DateTimeFormat.prototype.formatToParts() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.formatToParts +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts +--- +{{JSRef}} + +**`Intl.DateTimeFormat.prototype.formatToParts()`** メソッドは、ロケールを考慮した {{jsxref("Intl.DateTimeFormat")}} フォーマッターが生成する文字列のロケールを考慮した書式化を可能にします。 + +## 構文 + +```js +formatToParts(date) +``` + +### 引数 + +- `date` {{optional_inline}} + - : 書式化する日付。 + +### 返値 + +{{jsxref("Array")}} で、書式化された日付のパーツを含むオブジェクトの配列です。 + +## 解説 + +`formatToParts()` メソッドは、日付文字列のフォーマットをカスタマイズするときに役立ちます。これは、ロケール特有の部分を保持しながら、カスタム文字列を構築できるロケール特有のトークンを含むオブジェクトの {{jsxref("Array")}} を返します。`formatToParts()` メソッドが返却する構造は、このようになります。 + +```js +[ + { type: 'day', value: '17' }, + { type: 'weekday', value: 'Monday' } +] +``` + +渡される可能性がある type は以下のとおりです。 + +- day + - : 日付として使用される文字列。たとえば、 "`17`"。 +- dayPeriod + - : 日付期間として使用される文字列。たとえば、 "`AM`", "`PM`", "`in the morning`", "`noon`" など。 +- era + - : 時代として使用される文字列。たとえば、"`BC`" や "`AD`"。 +- fractionalSecond + - : 小数点以下の秒として使用される文字列です。例えば "`0`" や "`00`" や "`000`" です。 +- hour + - : 時刻として使用される文字列。たとえば "`3`" や "`03`"。 +- literal + - : 日付や時刻の区切りとして使用される文字列。たとえば "`/`"、"`,`"、"`o'clock`"、"`de`"。 +- minute + - : 分として使用される文字列。たとえば、"`00`"。 +- month + - : 月として使用される文字列。たとえば、"`12`"。 +- relatedYear + - : カレンダーの表現が year ではなくyearNameである場合、関連する4桁のグレゴリオ暦の年に使用される文字列です。例えば "`2019`" です。 +- second + - : 秒として使用される文字列。たとえば、"`07`" や "`42`"。 +- timeZoneName + - : タイムゾーン名として使用される文字列。たとえば、"`UTC`"。 +- weekday + - : 曜日として使用される文字列。たとえば、"`M`" や "`Monday`"、"`Montag`"。 +- year + - : 年として使用される文字列。たとえば、"`2012`" や "`96`"。 +- yearName + - : 関連するコンテキストで yearName に使用される文字列、例えば "`geng-zi`" など。 + +## ポリフィル + +この機能のポリフィルは、[提案リポジトリー](https://github.com/zbraniecki/proposal-intl-formatToParts)から利用できます。 + +## 例 + +`DateTimeFormat` は、直接操作できないローカライズされた透過的でない文字列を出力します。 + +```js +var date = Date.UTC(2012, 11, 17, 3, 0, 42); + +var formatter = new Intl.DateTimeFormat('en-us', { + weekday: 'long', + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + fractionalSecondDigits: 3, + hour12: true, + timeZone: 'UTC' +}); + +formatter.format(date); +// "Monday, 12/17/2012, 3:00:42.000 AM" +``` + +しかし、多くのユーザーインターフェイスでは、この文字列の書式をカスタマイズしたいという要望があります。 `formatToParts` メソッドは、文字列を部品単位で提供することで、 `DateTimeFormat` フォーマッターによって生成された文字列のロケールを意識した書式設定ができるようになります。 + +```js +formatter.formatToParts(date); + +// return value: +[ + { type: 'weekday', value: 'Monday' }, + { type: 'literal', value: ', ' }, + { type: 'month', value: '12' }, + { type: 'literal', value: '/' }, + { type: 'day', value: '17' }, + { type: 'literal', value: '/' }, + { type: 'year', value: '2012' }, + { type: 'literal', value: ', ' }, + { type: 'hour', value: '3' }, + { type: 'literal', value: ':' }, + { type: 'minute', value: '00' }, + { type: 'literal', value: ':' }, + { type: 'second', value: '42' }, + { type: 'fractionalSecond', value: '000' }, + { type: 'literal', value: ' ' }, + { type: 'dayPeriod', value: 'AM' } +] +``` + +これで情報は個別に利用可能になり、カスタマイズされた方法で再び書式化して連結することができます。例えば、{{jsxref("Array.prototype.map()")}}、アロー関数switch 文テンプレートリテラル、 {{jsxref("Array.prototype.join()")}} などを使用しています。 + +```js +var dateString = formatter.formatToParts(date).map(({type, value}) => { + switch (type) { + case 'dayPeriod': return `${value}`; + default : return value; + } +}).join(''); +``` + +これにより、 `formatToParts()` メソッドを使用する際に、日の部分が太字になります。 + +```js +console.log(formatter.format(date)); +// "Monday, 12/17/2012, 3:00:42.000 AM" + +console.log(dateString); +// "Monday, 12/17/2012, 3:00:42.000 AM" +``` + +### 名前付きの年と混合カレンダー + +名前付きの年を使用している暦もあります。例えば、中国やチベットの暦では、 60 年周期の[干支](https://ja.wikipedia.org/wiki/%E5%B9%B2%E6%94%AF)を使用しています。これらの年は、グレゴリオ暦の年と関連付けて識別されます。このような場合、 `formatToParts()` の結果は、通常は年が存在するはずなのに、年の項目ではなく、 4 桁のグレゴリオ暦の年を含む `relatedYear` の項目を含むことになります。バッグの中の項目を (任意の値で) `year` に設定すると、年と `yearName` グレゴリオ暦の `relatedYear` の両方が得られます。 + +```js +let opts = { year: "numeric", month: "numeric", day: "numeric" }; +let df = new Intl.DateTimeFormat("zh-u-ca-chinese", opts); +df.formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42)); + +// return value +[ + { type: 'relatedYear', value: '2012' }, + { type: 'literal', value: '年' }, + { type: 'month', value: '十一月' }, + { type: 'day', value: '4' } +] +``` + +`year` オプションがバッグ内で設定されていない場合 (任意の値に設定されている場合)、結果には `relatedYear` のみが含まれます。 + +```js +let df = new Intl.DateTimeFormat("zh-u-ca-chinese"); +df.formatToParts(Date.UTC(2012, 11, 17, 3, 0, 42)); + +// 返値 +[ + { type: 'relatedYear', value: '2012' }, + { type: 'literal', value: '年' }, + { type: 'month', value: '十一月' }, + { type: 'day', value: '4' } +] +``` + +`year` を出力したい場合は、 `.format()` は一般的にこれらを並べて表示することができます。 + +```js +let df = new Intl.DateTimeFormat("zh-u-ca-chinese", {year: "numeric"}); +df.format(Date.UTC(2012, 11, 17, 3, 0, 42)); + +// 返値 +2012壬辰年 +``` + +これにより、ロケールとカレンダーを両方の `format` で混在させることも可能になります。 + +```js +let df = new Intl.DateTimeFormat("en-u-ca-chinese", {year: "numeric"}); +let date = Date.UTC(2012, 11, 17, 3, 0, 42); +df.format(date); + +// 返値 +2012(ren-chen) +``` + +および `formatToParts` の場合 + +```js +let opts = {month: 'numeric', day: 'numeric', year: "numeric"}; +let df = new Intl.DateTimeFormat("en-u-ca-chinese", opts); +let date = Date.UTC(2012, 11, 17, 3); +df.formatToParts(date) + +// 返値 +[ + { type: 'month', value: '11' }, + { type: 'literal', value: '/' }, + { type: 'day', value: '4' }, + { type: 'literal', value: '/' }, + { type: 'relatedYear', value: '2012' } +] +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.DateTimeFormat")}} +- {{jsxref("Intl/DateTimeFormat/format", "Intl.DateTimeFormat.prototype.format()")}} +- {{jsxref("Date.prototype.toLocaleString()")}} +- {{jsxref("Date.prototype.toLocaleDateString()")}} +- {{jsxref("Date.prototype.toLocaleTimeString()")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html deleted file mode 100644 index 9b18a60a81..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.html +++ /dev/null @@ -1,182 +0,0 @@ ---- -title: Intl.DateTimeFormat -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat -tags: - - Class - - DateTimeFormat - - Internationalization - - Intl - - JavaScript - - Localization - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat -browser-compat: javascript.builtins.Intl.DateTimeFormat ---- -
{{JSRef}}
- -

Intl.DateTimeFormat オブジェクトは、言語に応じた日付と時刻の書式化を可能にするオブジェクトのためのコンストラクターです。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html")}}
- -

コンストラクター

- -
-
{{jsxref("Intl/DateTimeFormat/DateTimeFormat", "Intl.DateTimeFormat()")}}
-
新しい DateTimeFormat オブジェクトを生成します。
-
- -

静的メソッド

- -
-
{{jsxref("Intl/DateTimeFormat/supportedLocalesOf", "Intl.DateTimeFormat.supportedLocalesOf()")}}
-
指定されたロケールのうち、実行時の既定のロケールにフォールバックせずに対応されるものを配列に収めて返します。
-
- -

インスタンスメソッド

- -
-
{{jsxref("Intl/DateTimeFormat/format", "Intl.DateTimeFormat.prototype.format()")}}
-
ロケールおよびこの {{jsxref("Intl/DateTimeFormat", "DateTimeFormat")}} オブジェクトの書式化オプションに則って日付を書式化するゲッター関数です。
-
{{jsxref("Intl/DateTimeFormat/formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}
-
オブジェクトの {{jsxref("Array")}} を返し、これは専用のロケールを意識した書式で使用することができる部品内の数値文字列を表します。
-
{{jsxref("Intl/DateTimeFormat/resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}
-
ローケルを反映しているプロパティとオブジェクトの初期化中に計算された照合オプションをもった新しいオブジェクトを返します。
-
{{jsxref("Intl/DateTimeFormat/formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}}
-
このメソッドは 2 つの Date を受け取り、 {{jsxref("Intl/DateTimeFormat", "DateTimeFormat")}} インスタンスを生成する際に指定されたロケールとオプションに基づいて、最も簡潔な方法で日付の範囲を書式化します。
-
{{jsxref("Intl/DateTimeFormat/formatRangeToParts", "Intl.DateTimeFormat.prototype.formatRangeToParts()")}}
-
このメソッドは 2 つの Date を受け取り、書式化された日付の範囲の各部分を表すロケール固有のトークンを含むオブジェクトの配列を返します。
-
- -

- -

DateTimeFormat の使用

- -

基本的に、ロケールを指定せずに使用すると、 DateTimeFormat は既定のロケールとオプションを使用します。

- -
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
-
-// toLocaleString without arguments depends on the implementation,
-// the default locale, and the default time zone
-console.log(new Intl.DateTimeFormat().format(date));
-// → "12/19/2012" if run with en-US locale (language) and time zone America/Los_Angeles (UTC-0800)
-
- -

locales の使用

- -

この例では、ローカライズされた日付と時刻の形式のバリエーションの一部示しています。アプリケーションのユーザーインターフェイスで使用される言語のフォーマットを取得するには、 locales 引数を使用して、その言語 (およびおそらくいくつかのフォールバック言語) を指定してください。

- -
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
-
-// Results below use the time zone of America/Los_Angeles (UTC-0800, Pacific Standard Time)
-
-// US English uses month-day-year order
-console.log(new Intl.DateTimeFormat('en-US').format(date));
-// → "12/19/2012"
-
-// British English uses day-month-year order
-console.log(new Intl.DateTimeFormat('en-GB').format(date));
-// → "19/12/2012"
-
-// Korean uses year-month-day order
-console.log(new Intl.DateTimeFormat('ko-KR').format(date));
-// → "2012. 12. 19."
-
-// Arabic in most Arabic speaking countries uses real Arabic digits
-console.log(new Intl.DateTimeFormat('ar-EG').format(date));
-// → "١٩‏/١٢‏/٢٠١٢"
-
-// for Japanese, applications may want to use the Japanese calendar,
-// where 2012 was the year 24 of the Heisei era
-console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date));
-// → "24/12/19"
-
-// when requesting a language that may not be supported, such as
-// Balinese, include a fallback language, in this case Indonesian
-console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date));
-// → "19/12/2012"
-
- -

options の使用

- -

日付と時刻の書式は options 引数を使用してカスタマイズできます。

- -
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200));
-
-// request a weekday along with a long date
-var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
-console.log(new Intl.DateTimeFormat('de-DE', options).format(date));
-// → "Donnerstag, 20. Dezember 2012"
-
-// an application may want to use UTC and make that visible
-options.timeZone = 'UTC';
-options.timeZoneName = 'short';
-console.log(new Intl.DateTimeFormat('en-US', options).format(date));
-// → "Thursday, December 20, 2012, GMT"
-
-// sometimes you want to be more precise
-options = {
-  hour: 'numeric', minute: 'numeric', second: 'numeric',
-  timeZone: 'Australia/Sydney',
-  timeZoneName: 'short'
-};
-console.log(new Intl.DateTimeFormat('en-AU', options).format(date));
-// → "2:00:00 pm AEDT"
-
-// sometimes you want to be very precise
-options.fractionalSecondDigits = 3; //number digits for fraction-of-seconds
-console.log(new Intl.DateTimeFormat('en-AU', options).format(date));
-// → "2:00:00.200 pm AEDT"
-
-// sometimes even the US needs 24-hour time
-options = {
-  year: 'numeric', month: 'numeric', day: 'numeric',
-  hour: 'numeric', minute: 'numeric', second: 'numeric',
-  hour12: false,
-  timeZone: 'America/Los_Angeles'
-};
-console.log(new Intl.DateTimeFormat('en-US', options).format(date));
-// → "12/19/2012, 19:00:00"
-
-// to specify options but use the browser's default locale, use 'default'
-console.log(new Intl.DateTimeFormat('default', options).format(date));
-// → "12/19/2012, 19:00:00"
-
-// sometimes it's helpful to include the period of the day
-options = {hour: "numeric", dayPeriod: "short"};
-console.log(new Intl.DateTimeFormat('en-US', options).format(date));
-// → 10 at night
-
- -

The used calendar and numbering formats can also be set independently via options arguments:

- -
var options = {calendar: 'chinese', numberingSystem: 'arab'};
-var dateFormat = new Intl.DateTimeFormat('default', options);
-var usedOptions = dateFormat.resolvedOptions();
-
-console.log(usedOptions.calendar);
-// → "chinese"
-
-console.log(usedOptions.numberingSystem);
-// → "arab"
-
-console.log(usedOptions.timeZone);
-// → "America/New_York" (the users default timezone)
-
- -

ポリフィル

- -

formatjs Intl.DateTimeFormat polyfill

- -

仕様書

- -{{Specifications}} - -

ブラウザーの互換性

- -
{{Compat}}
- -

関連情報

- -
    -
  • {{jsxref("Intl")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.md new file mode 100644 index 0000000000..95faa9574f --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/index.md @@ -0,0 +1,179 @@ +--- +title: Intl.DateTimeFormat +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat +tags: + - Class + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat +browser-compat: javascript.builtins.Intl.DateTimeFormat +--- +{{JSRef}} + +**`Intl.DateTimeFormat`** オブジェクトは、言語に応じた日付と時刻の書式化を可能にします。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat.html")}} + + +## コンストラクター + +- {{jsxref("Intl/DateTimeFormat/DateTimeFormat", "Intl.DateTimeFormat()")}} + - : 新しい `DateTimeFormat` オブジェクトを生成します。 + +## 静的メソッド + +- {{jsxref("Intl/DateTimeFormat/supportedLocalesOf", "Intl.DateTimeFormat.supportedLocalesOf()")}} + - : 指定されたロケールのうち、実行時の既定のロケールにフォールバックせずに対応されるものを配列に収めて返します。 + +## インスタンスメソッド + +- {{jsxref("Intl/DateTimeFormat/format", "Intl.DateTimeFormat.prototype.format()")}} + - : ロケールおよびこの {{jsxref("Intl/DateTimeFormat", "DateTimeFormat")}} オブジェクトの書式化オプションに則って日付を書式化するゲッター関数です。 +- {{jsxref("Intl/DateTimeFormat/formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}} + - : オブジェクトの {{jsxref("Array")}} を返し、これは専用のロケールを意識した書式で使用することができる部品内の数値文字列を表します。 +- {{jsxref("Intl/DateTimeFormat/resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}} + - : ローケルを反映しているプロパティとオブジェクトの初期化中に計算された照合オプションをもった新しいオブジェクトを返します。 +- {{jsxref("Intl/DateTimeFormat/formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}} + - : このメソッドは 2 つの [Date](/ja/docs/Web/JavaScript/Reference/Global_Objects/Date) を受け取り、 {{jsxref("Intl/DateTimeFormat", "DateTimeFormat")}} インスタンスを生成する際に指定されたロケールとオプションに基づいて、最も簡潔な方法で日付の範囲を書式化します。 +- {{jsxref("Intl/DateTimeFormat/formatRangeToParts", "Intl.DateTimeFormat.prototype.formatRangeToParts()")}} + - : このメソッドは 2 つの [Date](/ja/docs/Web/JavaScript/Reference/Global_Objects/Date) を受け取り、書式化された日付の範囲の各部分を表すロケール固有のトークンを含むオブジェクトの配列を返します。 + +## 例 + +### DateTimeFormat の使用 + +基本的に、ロケールを指定せずに使用すると、 `DateTimeFormat` は既定のロケールとオプションを使用します。 + +```js +var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); + +// toLocaleString without arguments depends on the implementation, +// the default locale, and the default time zone +console.log(new Intl.DateTimeFormat().format(date)); +// → "12/19/2012" if run with en-US locale (language) and time zone America/Los_Angeles (UTC-0800) +``` + +### locales の使用 + +この例では、ローカライズされた日付と時刻の形式のバリエーションの一部示しています。アプリケーションのユーザーインターフェイスで使用される言語のフォーマットを取得するには、 `locales` 引数を使用して、その言語 (およびおそらくいくつかのフォールバック言語) を指定してください。 + +```js +var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); + +// Results below use the time zone of America/Los_Angeles (UTC-0800, Pacific Standard Time) + +// US English uses month-day-year order +console.log(new Intl.DateTimeFormat('en-US').format(date)); +// → "12/19/2012" + +// British English uses day-month-year order +console.log(new Intl.DateTimeFormat('en-GB').format(date)); +// → "19/12/2012" + +// Korean uses year-month-day order +console.log(new Intl.DateTimeFormat('ko-KR').format(date)); +// → "2012. 12. 19." + +// Arabic in most Arabic speaking countries uses real Arabic digits +console.log(new Intl.DateTimeFormat('ar-EG').format(date)); +// → "١٩‏/١٢‏/٢٠١٢" + +// for Japanese, applications may want to use the Japanese calendar, +// where 2012 was the year 24 of the Heisei era +console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date)); +// → "24/12/19" + +// when requesting a language that may not be supported, such as +// Balinese, include a fallback language, in this case Indonesian +console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date)); +// → "19/12/2012" +``` + +### options の使用 + +日付と時刻の書式は `options` 引数を使用してカスタマイズできます。 + +```js +var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200)); + +// request a weekday along with a long date +var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; +console.log(new Intl.DateTimeFormat('de-DE', options).format(date)); +// → "Donnerstag, 20. Dezember 2012" + +// an application may want to use UTC and make that visible +options.timeZone = 'UTC'; +options.timeZoneName = 'short'; +console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +// → "Thursday, December 20, 2012, GMT" + +// sometimes you want to be more precise +options = { + hour: 'numeric', minute: 'numeric', second: 'numeric', + timeZone: 'Australia/Sydney', + timeZoneName: 'short' +}; +console.log(new Intl.DateTimeFormat('en-AU', options).format(date)); +// → "2:00:00 pm AEDT" + +// sometimes you want to be very precise +options.fractionalSecondDigits = 3; //number digits for fraction-of-seconds +console.log(new Intl.DateTimeFormat('en-AU', options).format(date)); +// → "2:00:00.200 pm AEDT" + +// sometimes even the US needs 24-hour time +options = { + year: 'numeric', month: 'numeric', day: 'numeric', + hour: 'numeric', minute: 'numeric', second: 'numeric', + hour12: false, + timeZone: 'America/Los_Angeles' +}; +console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +// → "12/19/2012, 19:00:00" + +// to specify options but use the browser's default locale, use 'default' +console.log(new Intl.DateTimeFormat('default', options).format(date)); +// → "12/19/2012, 19:00:00" + +// sometimes it's helpful to include the period of the day +options = {hour: "numeric", dayPeriod: "short"}; +console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +// → 10 at night +``` + +The used calendar and numbering formats can also be set independently via `options` arguments: + +```js +var options = {calendar: 'chinese', numberingSystem: 'arab'}; +var dateFormat = new Intl.DateTimeFormat('default', options); +var usedOptions = dateFormat.resolvedOptions(); + +console.log(usedOptions.calendar); +// → "chinese" + +console.log(usedOptions.numberingSystem); +// → "arab" + +console.log(usedOptions.timeZone); +// → "America/New_York" (the users default timezone) +``` + +## ポリフィル + +[formatjs Intl.DateTimeFormat polyfill](https://formatjs.io/docs/polyfills/intl-datetimeformat) + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html deleted file mode 100644 index c59e62e79c..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.html +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: Intl.DateTimeFormat.prototype.resolvedOptions() -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions -tags: - - DateTimeFormat - - Internationalization - - Intl - - JavaScript - - Method - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions ---- -
{{JSRef}}
- -

Intl.Collator.prototype.resolvedOptions() メソッドは、この {{jsxref("Collator")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトを返します。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-resolvedoptions.html")}}
- - - -

構文

- -
dateTimeFormat.resolvedOptions()
- -

返値

- -

この {{jsxref("DateTimeFormat")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトです。

- -

解説

- -

返されるオブジェクトには以下のプロパティがあります。

- -
-
locale
-
実際に使用したロケールの BCP 47 言語タグ。このロケールにつながる入力 BCP 47 言語タグに Unicode 拡張値が要求された場合、要求されたキーと値のペアのうち、このロケールで対応しているものが locale に含まれます。
-
calendar
-
例: "gregory"
-
numberingSystem
-
Unicode 拡張キーの "ca" および "nu" で要求された値、または既定値が入ります。
-
timeZone
-
options 引数の同名のプロパティで要求された値です。提供された値がなければ {{jsxref("undefined")}} (ランタイムの既定のタイムゾーン) です。警告: アプリケーションは {{jsxref("undefined")}} が返されることに依存しないでください。将来のバージョンではランタイムの既定のタイムゾーンを識別する {{jsxref("String")}} 値が返されるようになる可能性があるからです。
-
hour12
-
options 引数の同名のプロパティで要求された値、または既定値が入ります。
-
weekday
-
era
-
year
-
month
-
day
-
hour
-
minute
-
second
-
timeZoneName
-
options 引数の対応するプロパティと、選択したロケールでの日付時刻の書式設定に利用可能な組み合わせや表現との間で、書式のマッチングを行った結果の値。これらのプロパティの中には、対応するコンポーネントが書式化された出力では表現されないものもあります。
-
- -

- -

resolvedOptions メソッドの使用

- -
var germanFakeRegion = new Intl.DateTimeFormat('de-XX', { timeZone: 'UTC' });
-var usedOptions = germanFakeRegion.resolvedOptions();
-
-usedOptions.locale;          // "de"
-usedOptions.calendar;        // "gregory"
-usedOptions.numberingSystem; // "latn"
-usedOptions.timeZone;        // "UTC"
-usedOptions.month;           // "numeric"
-
- -

仕様書

- - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-intl.datetimeformat.prototype.resolvedoptions', 'Intl.DateTimeFormat.prototype.resolvedOptions')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.DateTimeFormat.resolvedOptions")}}

-
- -

関連情報

- -
    -
  • {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md new file mode 100644 index 0000000000..6ceb4c773f --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md @@ -0,0 +1,75 @@ +--- +title: Intl.DateTimeFormat.prototype.resolvedOptions() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.resolvedOptions +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions +--- +{{JSRef}} + +**`Intl.DateTimeFormat.prototype.resolvedOptions()`** メソッドは、この {{jsxref("Intl/DateTimeFormat")}} オブジェクトの初期化時に計算されたロケールや日付と時刻の整形オプションを反映したプロパティを持つ新しいオブジェクトを返します。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-resolvedoptions.html")}} + + +## 構文 + +```js +resolvedOptions() +``` + +### 返値 + +この {{jsxref("Intl/DateTimeFormat")}} オブジェクトの初期化時に計算されたロケールと照合オプションを反映したプロパティを持つ新しいオブジェクトです。 + +## 解説 + +返されるオブジェクトには以下のプロパティがあります。 + +- `locale` + - : 実際に使用したロケールの BCP 47 言語タグ。このロケールにつながる入力 BCP 47 言語タグに Unicode 拡張値が要求された場合、要求されたキーと値のペアのうち、このロケールで対応しているものが `locale` に含まれます。 +- `calendar` + - : 例: "gregory" +- `numberingSystem` + - : Unicode 拡張キーの `"ca"` および `"nu"` で要求された値、または既定値が入ります。 +- `timeZone` + - : `options` 引数の同名のプロパティで要求された値です。提供された値がなければ {{jsxref("undefined")}} (ランタイムの既定のタイムゾーン) です。警告: アプリケーションは {{jsxref("undefined")}} が返されることに依存しないでください。将来のバージョンではランタイムの既定のタイムゾーンを識別する {{jsxref("String")}} 値が返されるようになる可能性があるからです。 +- `hour12` + - : `options` 引数の同名のプロパティで要求された値、または既定値が入ります。 +- `weekday`, `era`, `year`, `month`, `day`, `hour`, `minute`, `second`, `timeZoneName` + - : `options` 引数の対応するプロパティと、選択したロケールでの日付時刻の書式設定に利用可能な組み合わせや表現との間で、書式のマッチングを行った結果の値。これらのプロパティの中には、対応するコンポーネントが書式化された出力では表現されないものもあります。 + +## 例 + +### resolvedOptions メソッドの使用 + +```js +var germanFakeRegion = new Intl.DateTimeFormat('de-XX', { timeZone: 'UTC' }); +var usedOptions = germanFakeRegion.resolvedOptions(); + +usedOptions.locale; // "de" +usedOptions.calendar; // "gregory" +usedOptions.numberingSystem; // "latn" +usedOptions.timeZone; // "UTC" +usedOptions.month; // "numeric" +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.DateTimeFormat")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html deleted file mode 100644 index 0108a95679..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.html +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: Intl.DateTimeFormat.supportedLocalesOf() -slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf -tags: - - DateTimeFormat - - Internationalization - - JavaScript - - Method - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf ---- -
{{JSRef}}
- -

Intl.DateTimeFormat.supportedLocalesOf() メソッドは、ランタイムの既定のロケールで代替する必要なく日時の書式で対応されているものを含む配列を返します。

- -
{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-supportedlocalesof.html","shorter")}}
- - - -

構文

- -
Intl.DateTimeFormat.supportedLocalesOf(locales[, options])
- -

引数

- -
-
locales
-
BCP 47 言語タグを持つ文字列、またはそのような文字列の配列です。 locales 引数の一般的な形式については、 {{jsxref("Intl", "Intl のページ", "#Locale_identification_and_negotiation", 1)}}を参照してください。
-
options
-
-

省略可能です。以下のプロパティを持つことがあるオブジェクトです。

- -
-
localeMatcher
-
使用するロケールの一致アルゴリズムです。指定可能な値は lookup および best fit で、既定値は best fit です。このオプションの詳細は、 {{jsxref("Intl", "Intl のページ", "#Locale_negotiation", 1)}}を参照してください。
-
-
-
- -

返値

- -

指定したロケールタグのサブセットを表す文字列の配列で、ランタイムの既定のロケールで代替する必要なく日時の書式で対応されているものを含みます。

- -

解説

- -

locales で提供されている言語タグのサブセットを含む配列を返します。返される言語タグは、ランタイムが日時のロケールに対応しているもので、使用しているロケール一致アルゴリズムで一致しているとみなされているものです。

- -

- -

supportedLocalesOf() の使用

- -

日時の書式でインドネシア語とドイツ語に対応しており、バリ語に対応していないランタイムを想定すると、 supportedLocalesOf はインドネシア語とドイツ語の言語タグを変更せずに返しますが、 pinyin の照合は日時の書式には関係なく、インドネシア語でも使用されません。ここでの lookup アルゴリズムの仕様に注意してください — バリ語話者のほとんどはインドネシア語も理解しているので、 best fit のマッチャーはインドネシア語がバリ語に適切に一致すると判断し、バリ語の言語タグも返すかもしれません。

- -
var locales = ['ban', 'id-u-co-pinyin', 'de-ID'];
-var options = { localeMatcher: 'lookup' };
-console.log(Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(', '));
-// → "id-u-co-pinyin, de-ID"
-
- -

仕様書

- - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-intl.datetimeformat.supportedlocalesof', 'Intl.DateTimeFormat.supportedLocalesOf')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.DateTimeFormat.supportedLocalesOf")}}

-
- -

関連情報

- -
    -
  • {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md new file mode 100644 index 0000000000..4c5e19d610 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md @@ -0,0 +1,71 @@ +--- +title: Intl.DateTimeFormat.supportedLocalesOf() +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf +tags: + - DateTimeFormat + - Internationalization + - Intl + - JavaScript + - Localization + - Method + - Reference +browser-compat: javascript.builtins.Intl.DateTimeFormat.supportedLocalesOf +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf +--- +{{JSRef}} + +**`Intl.DateTimeFormat.supportedLocalesOf()`** メソッドは、ランタイムの既定のロケールで代替する必要なく日時の書式で対応されているものを含む配列を返します。 + +{{EmbedInteractiveExample("pages/js/intl-datetimeformat-prototype-supportedlocalesof.html","shorter")}} + + +## 構文 + +```js +Intl.DateTimeFormat.supportedLocalesOf(locales) +Intl.DateTimeFormat.supportedLocalesOf(locales, options) +``` + +### 引数 + +- `locales` + - : BCP 47 言語タグを持つ文字列、またはそのような文字列の配列です。 `locales` 引数の一般的な形式については、 {{jsxref("Intl", "Intl", "#Locale_identification_and_negotiation", 1)}} のページを参照してください。 +- `options` {{optional_inline}} + + - : 省略可能です。以下のプロパティを持つことがあるオブジェクトです。 + + - `localeMatcher` + - : 使用するロケールの一致アルゴリズムです。指定可能な値は `lookup` および `best fit` で、既定値は `best fit` です。このオプションの詳細は、 {{jsxref("Intl", "Intl", "#Locale_negotiation", 1)}} のページを参照してください。 + +### 返値 + +指定したロケールタグのサブセットを表す文字列の配列で、ランタイムの既定のロケールで代替する必要なく日時の書式で対応されているものを含みます。 + +## 解説 + +`locales` で提供されている言語タグのサブセットを含む配列を返します。返される言語タグは、ランタイムが日時のロケールに対応しているもので、使用しているロケール一致アルゴリズムで一致しているとみなされているものです。 + +## 例 + +### supportedLocalesOf() の使用 + +日時の書式でインドネシア語とドイツ語に対応しており、バリ語に対応していないランタイムを想定すると、 `supportedLocalesOf` はインドネシア語とドイツ語の言語タグを変更せずに返しますが、 pinyin の照合は日時の書式には関係なく、インドネシア語でも使用されません。ここでの `lookup` アルゴリズムの仕様に注意してください — バリ語話者のほとんどはインドネシア語も理解しているので、 `best fit` のマッチャーはインドネシア語がバリ語に適切に一致すると判断し、バリ語の言語タグも返すかもしれません。 + +```js +const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; +const options = { localeMatcher: 'lookup' }; +console.log(Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(', ')); +// → "id-u-co-pinyin, de-ID" +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.DateTimeFormat")}} -- cgit v1.2.3-54-g00ecf From 8fd187f66427d1181bf7cfd225360cc267a73f2b Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sat, 28 Aug 2021 10:49:57 +0900 Subject: Global_Objects/Object/propertyIsEnumerable を更新 (#2149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Markdown に変換、 2021/07/21 時点の英語版に同期 --- .../object/propertyisenumerable/index.html | 133 --------------------- .../object/propertyisenumerable/index.md | 120 +++++++++++++++++++ 2 files changed, 120 insertions(+), 133 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.html b/files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.html deleted file mode 100644 index d2d7ba68e7..0000000000 --- a/files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.html +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: Object.prototype.propertyIsEnumerable() -slug: Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable -tags: - - JavaScript - - Method - - Object - - Prototype - - プロトタイプ - - メソッド -translation_of: Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable ---- -
{{JSRef}}
- -

propertyIsEnumerable() メソッドは、指定されたプロパティが列挙可能で、オブジェクト自身のプロパティであることを示す Boolean を返します。

- -
{{EmbedInteractiveExample("pages/js/object-prototype-propertyisenumerable.html", "taller")}}
- - - -

構文

- -
obj.propertyIsEnumerable(prop)
- -

引数

- -
-
prop
-
調べたいプロパティの名前。
-
- -

返値

- -

指定されたプロパティが列挙可能であり、かつオブジェクト自体のプロパティであるかどうかを示す {{jsxref("Boolean")}} 。

- -

解説

- -

すべてのオブジェクトは propertyIsEnumerable メソッドを持っています。このメソッドはあるオブジェクトのプロパティが、プロトタイプチェーンを通じて継承されたプロパティを除いて {{jsxref("Statements/for...in", "for...in")}} ループで列挙可能かどうかを特定することができます。もしオブジェクトが指定されたプロパティを持っていない場合、このメソッドは false を返します。

- -

- -

propertyIsEnumerable の基本的な使い方

- -

以下の例はオブジェクトと配列での propertyIsEnumerable の使い方を示しています。

- -
var o = {};
-var a = [];
-o.prop = 'is enumerable';
-a[0] = 'is enumerable';
-
-o.propertyIsEnumerable('prop');   // true を返す
-a.propertyIsEnumerable(0);        // true を返す
-
- -

ユーザー定義オブジェクトと組み込みオブジェクト

- -

以下の例はユーザー定義プロパティと組み込みプロパティの列挙可能性を実証しています。

- -
var a = ['is enumerable'];
-
-a.propertyIsEnumerable(0);          // true を返す
-a.propertyIsEnumerable('length');   // false を返す
-
-Math.propertyIsEnumerable('random');   // false を返す
-this.propertyIsEnumerable('Math');     // false を返す
-
- -

直接のプロパティと継承されたプロパティ

- -
var a = [];
-a.propertyIsEnumerable('constructor');         // false を返す
-
-function firstConstructor() {
-  this.property = 'is not enumerable';
-}
-
-firstConstructor.prototype.firstMethod = function() {};
-
-function secondConstructor() {
-  this.method = function method() { return 'is enumerable'; };
-}
-
-secondConstructor.prototype = new firstConstructor;
-secondConstructor.prototype.constructor = secondConstructor;
-
-var o = new secondConstructor();
-o.arbitraryProperty = 'is enumerable';
-
-o.propertyIsEnumerable('arbitraryProperty');   // true を返す
-o.propertyIsEnumerable('method');              // true を返す
-o.propertyIsEnumerable('property');            // false を返す
-
-o.property = 'is enumerable';
-
-o.propertyIsEnumerable('property');            // true を返す
-
-// これらはすべて false を返します。これは、 (最後の2つは for-in で
-// 反復処理可能であるにもかかわらず) propertyIsEnumerable が考慮しない
-// プロトタイプであるためです。
-o.propertyIsEnumerable('prototype');   // false を返す (as of JS 1.8.1/FF3.6)
-o.propertyIsEnumerable('constructor'); // false を返す
-o.propertyIsEnumerable('firstMethod'); // false を返す
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-object.prototype.propertyisenumerable', 'Object.prototype.propertyIsEnumerable')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Object.propertyIsEnumerable")}}

-
- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.md b/files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.md new file mode 100644 index 0000000000..c2b09a9921 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/object/propertyisenumerable/index.md @@ -0,0 +1,120 @@ +--- +title: Object.prototype.propertyIsEnumerable() +slug: Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable +tags: + - JavaScript + - メソッド + - Object + - プロトタイプ +browser-compat: javascript.builtins.Object.propertyIsEnumerable +translation_of: Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable +--- +{{JSRef}} + +**`propertyIsEnumerable()`** メソッドは、指定されたプロパティが列挙可能で、かつオブジェクト自身のプロパティであるかどうかを示す論理値を返します。 + +{{EmbedInteractiveExample("pages/js/object-prototype-propertyisenumerable.html", "taller")}} + +## 構文 + +```js +propertyIsEnumerable(prop) +``` + +### 引数 + +- `prop` + - : 調べたいプロパティの名前です。 + +### 返値 + +`true` または `false` の値で、指定されたプロパティが列挙可能であり、かつオブジェクト自身のプロパティであるかどうかを示します。 + +## 解説 + +すべてのオブジェクトは `propertyIsEnumerable` メソッドを持っています。このメソッドはあるオブジェクトのプロパティが、プロトタイプチェーンを通じて継承されたプロパティを除いて {{jsxref("Statements/for...in", "for...in")}} ループで列挙可能かどうかを特定することができます。もしオブジェクトが指定されたプロパティを持っていない場合、このメソッドは `false` を返します。 + +> **Note:** 列挙可能なプロパティは {{jsxref("Statements/for...in", "for...in")}} ループで反復処理されますが、 {{jsxref("Global_Objects/Symbol", "Symbol")}} は含まれないことに留意してください。 + +## 例 + +### `propertyIsEnumerable` の基本的な使い方 + +以下の例はオブジェクトと配列での `propertyIsEnumerable` の使い方を示しています。 + +```js +var o = {}; +var a = []; +o.prop = 'is enumerable'; +a[0] = 'is enumerable'; + +o.propertyIsEnumerable('prop'); // true を返す +a.propertyIsEnumerable(0); // true を返す +``` + +### ユーザー定義オブジェクトと組み込みオブジェクト + +以下の例は、ユーザー定義プロパティと組み込みプロパティの列挙可能性を実証しています。 + +```js +var a = ['is enumerable']; + +a.propertyIsEnumerable(0); // true を返す +a.propertyIsEnumerable('length'); // false を返す + +Math.propertyIsEnumerable('random'); // false を返す +this.propertyIsEnumerable('Math'); // false を返す +``` + +

直接のプロパティと継承されたプロパティ

+ +```js +var a = []; +a.propertyIsEnumerable('constructor'); // false を返す + +function firstConstructor() { + this.property = 'is not enumerable'; +} + +firstConstructor.prototype.firstMethod = function() {}; + +function secondConstructor() { + this.method = function() { return 'is enumerable'; }; +} + +secondConstructor.prototype = new firstConstructor; +secondConstructor.prototype.constructor = secondConstructor; + +var o = new secondConstructor(); +o.arbitraryProperty = 'is enumerable'; + +o.propertyIsEnumerable('arbitraryProperty'); // true を返す +o.propertyIsEnumerable('method'); // true を返す +o.propertyIsEnumerable('property'); // false を返す + +o.property = 'is enumerable'; + +o.propertyIsEnumerable('property'); // true を返す + +// これらはすべて false を返します。これは、 (最後の 2 つは for-in で +// 反復処理可能であるにもかかわらず) propertyIsEnumerable が考慮しない +// プロトタイプであるためです。 +o.propertyIsEnumerable('prototype'); // false を返す (as of JS 1.8.1/FF3.6) +o.propertyIsEnumerable('constructor'); // false を返す +o.propertyIsEnumerable('firstMethod'); // false を返す +``` + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- [列挙可能性とプロパティの所有権](/ja/docs/Web/JavaScript/Enumerability_and_ownership_of_properties) +- {{jsxref("Statements/for...in", "for...in")}} +- {{jsxref("Object.keys()")}} +- {{jsxref("Object.defineProperty()")}} -- cgit v1.2.3-54-g00ecf From e2b6fc2fd48db513519e1db978dc043a01a43b58 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sat, 28 Aug 2021 21:02:57 +0900 Subject: Web/JavaScript/Reference/Global_Objects/Reflect/construct を更新 (#2117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化 - 文書を最新の英語版に同期 --- .../global_objects/reflect/construct/index.html | 146 -------------------- .../global_objects/reflect/construct/index.md | 148 +++++++++++++++++++++ 2 files changed, 148 insertions(+), 146 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/reflect/construct/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/reflect/construct/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/reflect/construct/index.html b/files/ja/web/javascript/reference/global_objects/reflect/construct/index.html deleted file mode 100644 index 9bfefa49e2..0000000000 --- a/files/ja/web/javascript/reference/global_objects/reflect/construct/index.html +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: Reflect.construct() -slug: Web/JavaScript/Reference/Global_Objects/Reflect/construct -tags: - - ECMAScript 2015 - - JavaScript - - Method - - Reference - - Reflect - - メソッド -translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/construct ---- -
{{JSRef}}
- -

静的な Reflect.construct() メソッドは {{jsxref("Operators/new", "new")}} 演算子のように、ただし関数として動作します。これは new target(...args) の呼び出しと同等です。このメソッドはオプションを追加することで、別なプロトタイプを指定することができます。

- -
{{EmbedInteractiveExample("pages/js/reflect-construct.html", "taller")}}
- - - -

構文

- -
Reflect.construct(target, argumentsList[, newTarget])
-
- -

引数

- -
-
target
-
呼び出し対象の関数。
-
argumentsList
-
配列風オブジェクトで、 target の呼び出しの引数を指定する。
-
newTarget {{optional_inline}}
-
プロトタイプを使用するコンストラクター。 new.target も参照してください。 newTarget が存在しない場合は、既定値は target になります。
-
- -

返値

- -

target (または、もしあれば newTarget) の新しいインスタンスで、 targetargumentsList を渡してコンストラクターとして呼び出すことで初期化します。

- -

例外

- -

{{jsxref("TypeError")}}: target または newTarget がコンストラクターではない場合。

- -

解説

- -

Reflect.construct() によって、可変長引数を指定してコンストラクターを呼び出すことができます。 (これは new 演算子 を組み合わせて使用することでも可能です。)

- -
let obj = new Foo(...args)
-let obj = Reflect.construct(Foo, args)
-
- -

Reflect.construct()Object.create()

- -

Reflect が導入される前は、オブジェクトを構築するのにコンストラクターとプロトタイプの任意の組み合わせで {{jsxref("Object.create()")}} を使用して構築することができました。

- -
function OneClass() {
-    this.name = 'one'
-}
-
-function OtherClass() {
-    this.name = 'other'
-}
-
-// この呼び出しは、
-let obj1 = Reflect.construct(OneClass, args, OtherClass)
-
-// ...これと同じ結果をもたらします。
-let obj2 = Object.create(OtherClass.prototype)
-OneClass.apply(obj2, args)
-
-console.log(obj1.name)  // 'one'
-console.log(obj2.name)  // 'one'
-
-console.log(obj1 instanceof OneClass)  // false
-console.log(obj2 instanceof OneClass)  // false
-
-console.log(obj1 instanceof OtherClass)  // true
-console.log(obj2 instanceof OtherClass)  // true
-
- -

この2つの手法の最終結果は同じですが、その過程に重要な違いがあります。 Object.create() と {{jsxref("Function.prototype.apply()")}} を使用する場合、 new.target 演算子はコンストラクター内で undefined を返します。これは、 new 演算子を用いないためです。

- -

一方、 Reflect.construct() を呼び出す場合は、 new.target 演算子は、提供されていれば newTarget を指し、そうでなければ target を指します。

- -
function OneClass() {
-    console.log('OneClass')
-    console.log(new.target)
-}
-function OtherClass() {
-    console.log('OtherClass')
-    console.log(new.target)
-}
-
-let obj1 = Reflect.construct(OneClass, args)
-// Output:
-//     OneClass
-//     function OneClass { ... }
-
-let obj2 = Reflect.construct(OneClass, args, OtherClass)
-// Output:
-//     OneClass
-//     function OtherClass { ... }
-
-let obj3 = Object.create(OtherClass.prototype);
-OneClass.apply(obj3, args)
-// Output:
-//     OneClass
-//     undefined
-
- -

- -

Reflect.construct() の使用

- -
let d = Reflect.construct(Date, [1776, 6, 4])
-d instanceof Date  // true
-d.getFullYear()    // 1776
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-reflect.construct', 'Reflect.construct')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.Reflect.construct")}}

- -

関連情報

- -
    -
  • {{jsxref("Reflect")}}
  • -
  • {{jsxref("Operators/new", "new")}}
  • -
  • new.target
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/reflect/construct/index.md b/files/ja/web/javascript/reference/global_objects/reflect/construct/index.md new file mode 100644 index 0000000000..5cc425fa6d --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/reflect/construct/index.md @@ -0,0 +1,148 @@ +--- +title: Reflect.construct() +slug: Web/JavaScript/Reference/Global_Objects/Reflect/construct +tags: + - ECMAScript 2015 + - JavaScript + - Method + - Reference + - Reflect + - Polyfill +browser-compat: javascript.builtins.Reflect.construct +translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/construct +--- +{{JSRef}} + +静的な **`Reflect.construct()`** メソッドは {{jsxref("Operators/new", "new")}} 演算子のように、ただし関数として動作します。これは `new target(...args)` の呼び出しと同等です。このメソッドはオプションを追加することで、別なプロトタイプを指定することができます。 + +{{EmbedInteractiveExample("pages/js/reflect-construct.html", "taller")}} + +## 構文 + +```js +Reflect.construct(target, argumentsList) +Reflect.construct(target, argumentsList, newTarget) +``` + +### 引数 + +- `target` + - : 呼び出し対象の関数。 +- `argumentsList` + - : 配列風オブジェクトで、 `target` の呼び出しの引数を指定する。 +- `newTarget` {{optional_inline}} + - : プロトタイプを使用するコンストラクター。 [`new.target`](/ja/docs/Web/JavaScript/Reference/Operators/new.target) も参照してください。 `newTarget` が存在しない場合は、既定値は `target` になります。 + +### 返値 + +`target` (または、もしあれば `newTarget`) の新しいインスタンスで、 `target` に `argumentsList` を渡してコンストラクターとして呼び出すことで初期化します。 + +### 例外 + +{{jsxref("TypeError")}}: `target` または `newTarget` がコンストラクターではない場合。 + +## 解説 + +`Reflect.construct()` によって、可変長引数を指定してコンストラクターを呼び出すことができます。 (これは[スプレッド構文](/ja/docs/Web/JavaScript/Reference/Operators/Spread_syntax)と[`new` 演算子](/ja/docs/Web/JavaScript/Reference/Operators/new)を組み合わせて使用することでも可能です。) + +```js +let obj = new Foo(...args) +let obj = Reflect.construct(Foo, args) +``` + +### `Reflect.construct()` と `Object.create()` + +`Reflect` が導入される前は、オブジェクトを構築するのにコンストラクターとプロトタイプの任意の組み合わせで {{jsxref("Object.create()")}} を使用して構築することができました。 + + function OneClass() { + this.name = 'one' + } + + function OtherClass() { + this.name = 'other' + } + + // Calling this: + let obj1 = Reflect.construct(OneClass, args, OtherClass) + + // ...has the same result as this: + let obj2 = Object.create(OtherClass.prototype) + OneClass.apply(obj2, args) + + console.log(obj1.name) // 'one' + console.log(obj2.name) // 'one' + + console.log(obj1 instanceof OneClass) // false + console.log(obj2 instanceof OneClass) // false + + console.log(obj1 instanceof OtherClass) // true + console.log(obj2 instanceof OtherClass) // true + + //Another example to demonstrate below: + + function func1(a, b, c, d) { + console.log(arguments[3]); + } + + function func2(d, e, f, g) { + console.log(arguments[3]); + } + + let obj1 = Reflect.construct(func1, ['I', 'Love', 'my', 'India']) + obj1 + +この 2 つの手法の最終結果は同じですが、その過程に重要な違いがあります。 `Object.create()` と {{jsxref("Function.prototype.apply()")}} を使用する場合、 `new.target` 演算子はコンストラクター内で `undefined` を返します。これは、 `new` 演算子を用いないためです。 + +一方、 `Reflect.construct()` を呼び出す場合は、 `new.target` 演算子は、提供されていれば `newTarget` を指し、そうでなければ `target` を指します。 + +```js +function OneClass() { + console.log('OneClass') + console.log(new.target) +} +function OtherClass() { + console.log('OtherClass') + console.log(new.target) +} + +let obj1 = Reflect.construct(OneClass, args) +// Output: +// OneClass +// function OneClass { ... } + +let obj2 = Reflect.construct(OneClass, args, OtherClass) +// Output: +// OneClass +// function OtherClass { ... } + +let obj3 = Object.create(OtherClass.prototype); +OneClass.apply(obj3, args) +// Output: +// OneClass +// undefined +``` + +## 例 + +### `Reflect.construct()` の使用 + +```js +let d = Reflect.construct(Date, [1776, 6, 4]) +d instanceof Date // true +d.getFullYear() // 1776 +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- `Reflect.construct` のポリフィルが [`core-js`](https://github.com/zloirock/core-js#ecmascript-reflect) にあります +- {{jsxref("Reflect")}} +- {{jsxref("Operators/new", "new")}} +- [`new.target`](/ja/docs/Web/JavaScript/Reference/Operators/new.target) -- cgit v1.2.3-54-g00ecf From 864046f825665730c430a1fc9c03872364a94be7 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 30 Aug 2021 00:26:48 +0900 Subject: Global_Objects/Array/toString を更新 (#2181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化、2021/08/21時点の英語版に同期 --- .../global_objects/array/tostring/index.html | 71 ---------------------- .../global_objects/array/tostring/index.md | 60 ++++++++++++++++++ 2 files changed, 60 insertions(+), 71 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/array/tostring/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/array/tostring/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/array/tostring/index.html b/files/ja/web/javascript/reference/global_objects/array/tostring/index.html deleted file mode 100644 index c5f260f82e..0000000000 --- a/files/ja/web/javascript/reference/global_objects/array/tostring/index.html +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: Array.prototype.toString() -slug: Web/JavaScript/Reference/Global_Objects/Array/toString -tags: - - Array - - JavaScript - - Method - - Prototype -translation_of: Web/JavaScript/Reference/Global_Objects/Array/toString ---- -
{{JSRef}}
- -

toString() メソッドは、指定された配列とその要素を表す文字列を返します。

- -
{{EmbedInteractiveExample("pages/js/array-tostring.html","shorter")}}
- -

構文

- -
arr.toString()
- -

返値

- -

配列の要素を表す文字列です。

- -

解説

- -

{{jsxref("Array")}} オブジェクトは {{jsxref("Object")}} の toString メソッドを上書きしています。Array オブジェクトでは、toString メソッドは配列をつないで、配列のそれぞれの要素がカンマで区切られた 1 つの文字列を返します。

- -

配列が文字列値として表される必要がある場合や、配列が文字列の結合として参照される時、JavaScript は toString メソッドを自動的に呼び出します。

- -

ECMAScript 5 でのセマンティック

- -

JavaScript 1.8.5 (Firefox 4)以降、および ECMAScript 第 5 版では、toString() メソッドは一般化されており、すべてのオブジェクトで使用可能となっています。{{jsxref("Object.prototype.toString()")}} が呼び出され、その結果の値が返されます。

- -

- -

toString を使用する

- -
const array1 = [1, 2, 'a', '1a'];
-
-console.log(array1.toString());
-// expected output: "1,2,a,1a"
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-array.prototype.tostring', 'Array.prototype.toString')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Array.toString")}}

-
- -

関連情報

- -
    -
  • {{jsxref("Array.prototype.join()")}}
  • -
  • {{jsxref("Object.prototype.toSource()")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/array/tostring/index.md b/files/ja/web/javascript/reference/global_objects/array/tostring/index.md new file mode 100644 index 0000000000..17807b4e04 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/array/tostring/index.md @@ -0,0 +1,60 @@ +--- +title: Array.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Array/toString +tags: + - Array + - JavaScript + - Method + - Prototype +browser-compat: javascript.builtins.Array.toString +translation_of: Web/JavaScript/Reference/Global_Objects/Array/toString +--- +{{JSRef}} + +**`toString()`** メソッドは、指定された配列とその要素を表す文字列を返します。 + +{{EmbedInteractiveExample("pages/js/array-tostring.html","shorter")}} + +## 構文 + +```js +toString() +``` + +### 返値 + +配列の要素の文字列表現です。 + +## 解説 + +{{jsxref("Array")}} オブジェクトは {{jsxref("Object")}} の `toString` メソッドをオーバーライドしています。Array オブジェクトでは、`toString` メソッドは配列をつないで、配列のそれぞれの要素がカンマで区切られた 1 つの文字列を返します。 + +配列を文字列値として表す必要がある場合や、配列が文字列の結合として参照されるとき、JavaScript は `toString` メソッドを自動的に呼び出します。 + +### ECMAScript 5 でのセマンティック + +JavaScript 1.8.5 (Firefox 4) 以降、および ECMAScript 第 5 版では、`toString()` メソッドは一般化されており、すべてのオブジェクトで使用可能となっています。{{jsxref("Object.prototype.toString()")}} が呼び出され、その結果の値が返されます。 + +## 例 + +### toString の使用 + +```js +const array1 = [1, 2, 'a', '1a']; + +console.log(array1.toString()); +// 期待される出力: "1,2,a,1a" +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Array.prototype.join()")}} +- {{jsxref("Object.prototype.toSource()")}} -- cgit v1.2.3-54-g00ecf From 9a2e241a74e56a2f754a39b82bd0bf9016a494f4 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 30 Aug 2021 23:57:29 +0900 Subject: Global_Objects/Infinity を更新 (#2187) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化 - 2021/07/21 時点の英語版に同期 --- .../reference/global_objects/infinity/index.html | 68 ---------------------- .../reference/global_objects/infinity/index.md | 54 +++++++++++++++++ 2 files changed, 54 insertions(+), 68 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/infinity/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/infinity/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/infinity/index.html b/files/ja/web/javascript/reference/global_objects/infinity/index.html deleted file mode 100644 index bbd61bc49e..0000000000 --- a/files/ja/web/javascript/reference/global_objects/infinity/index.html +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: Infinity -slug: Web/JavaScript/Reference/Global_Objects/Infinity -tags: - - JavaScript - - Property - - Reference - - プロパティ -translation_of: Web/JavaScript/Reference/Global_Objects/Infinity ---- -
{{jsSidebar("Objects")}}
- -

グローバルプロパティ Infinity は無限大を表す数値です。

- -

{{js_property_attributes(0,0,0)}}

- -
{{EmbedInteractiveExample("pages/js/globalprops-infinity.html")}}
- - - -

解説

- -

Infinityグローバルオブジェクトのプロパティです。言い換えればグローバルスコープ内の変数です。

- -

Infinity の初期値は {{jsxref("Number.POSITIVE_INFINITY")}} です。Infinity という値 (正の無限大) は他のあらゆる数より大きい数です。

- -

この値は数学的に無限大のように振る舞います。詳しくは {{jsxref("Number.POSITIVE_INFINITY")}} を参照してください。

- -

ECMAScript 5 の仕様では、Infinity は読み取り専用です (JavaScript 1.8.5 / Firefox 4 にて実装)。

- -

- -

Infinity を使う

- -
console.log(Infinity          ); /* Infinity */
-console.log(Infinity + 1      ); /* Infinity */
-console.log(Math.pow(10, 1000)); /* Infinity */
-console.log(Math.log(0)       ); /* -Infinity */
-console.log(1 / Infinity      ); /* 0 */
-console.log(1 / 0             ); /* Infinity */
-
- -

仕様

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-value-properties-of-the-global-object-infinity', 'Infinity')}}
- -

ブラウザーの互換性

- -

{{Compat("javascript.builtins.parseInt")}}

- -

関連情報

- -
    -
  • {{jsxref("Number.NEGATIVE_INFINITY")}}
  • -
  • {{jsxref("Number.POSITIVE_INFINITY")}}
  • -
  • {{jsxref("Number.isFinite")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/infinity/index.md b/files/ja/web/javascript/reference/global_objects/infinity/index.md new file mode 100644 index 0000000000..85a48243b1 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/infinity/index.md @@ -0,0 +1,54 @@ +--- +title: Infinity +slug: Web/JavaScript/Reference/Global_Objects/Infinity +tags: + - JavaScript + - プロパティ + - リファレンス +browser-compat: javascript.builtins.Infinity +translation_of: Web/JavaScript/Reference/Global_Objects/Infinity +--- +{{jsSidebar("Objects")}} + +グローバルプロパティ **`Infinity`** は無限大を表す数値です。 + +{{js_property_attributes(0,0,0)}} + +{{EmbedInteractiveExample("pages/js/globalprops-infinity.html")}} + +## 解説 + +`Infinity` は*グローバルオブジェクト*のプロパティです。言い換えればグローバルスコープ内の変数です。 + +`Infinity` の初期値は {{jsxref("Number.POSITIVE_INFINITY")}} です。`Infinity` という値 (正の無限大) は他のあらゆる数より大きい数です。 + +この値は数学的に無限大のように振る舞います。詳しくは {{jsxref("Number.POSITIVE_INFINITY")}} を参照してください。 + +ECMAScript 5 の仕様では、`Infinity` は読み取り専用です (JavaScript 1.8.5 / Firefox 4 にて実装)。 + +## 例 + +### Infinity の使用 + +```js +console.log(Infinity ); /* Infinity */ +console.log(Infinity + 1 ); /* Infinity */ +console.log(Math.pow(10, 1000)); /* Infinity */ +console.log(Math.log(0) ); /* -Infinity */ +console.log(1 / Infinity ); /* 0 */ +console.log(1 / 0 ); /* Infinity */ +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Number.NEGATIVE_INFINITY")}} +- {{jsxref("Number.POSITIVE_INFINITY")}} +- {{jsxref("Number.isFinite")}} -- cgit v1.2.3-54-g00ecf From 56b71955f605c6774059dd8fb04178ad9c5d16ed Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 30 Aug 2021 23:57:53 +0900 Subject: Global_Objects/Intl/ListFormat/resolvedOptions を新規翻訳 (#2197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 2021/08/23 時点の英語版に基づき新規翻訳 --- .../intl/listformat/resolvedoptions/index.md | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 files/ja/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md b/files/ja/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md new file mode 100644 index 0000000000..1e52948607 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md @@ -0,0 +1,71 @@ +--- +title: Intl.ListFormat.prototype.resolvedOptions() +slug: Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions +tags: + - Internationalization + - Intl + - JavaScript + - ListFormat + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.ListFormat.resolvedOptions +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions +--- +{{JSRef}} + +**`Intl.ListFormat.prototype.resolvedOptions()`** メソッドは、現在の {{jsxref("Intl.ListFormat")}} オブジェクトの構築時に計算されたロケールとスタイル整形オプションを反映したプロパティを持つ新しいオブジェクトを返します。 + +## 構文 + +```js +listFormat.resolvedOptions() +``` + +### 返値 + +指定された {{jsxref("Intl.ListFormat")}} オブジェクトの構築時に計算されたロケールと整形オプションを反映したプロパティを持つオブジェクトです。 + +## 解説 + +`resolvedOptions()` から返されるオブジェクトには、以下のプロパティがあります。 + +- `locale` + - : 実際に使用したロケールの BCP 47 言語タグ。このロケールにつながる入力 BCP 47 言語タグに Unicode 拡張値が要求された場合、要求されたキーと値のペアのうち、このロケールで対応しているものが `locale` に含まれます。 +- `style` + - : コンストラクターの `options` 引数の中でこのプロパティに指定された値、または既定値 ("`long`") がです。この値は、"`long`"、"`short`"、"`narrow`" のいずれかです。 +- `type` + - : コンストラクターの `options` 引数の中でこのプロパティに指定された値、または既定値 ("`conjunction`") がです。この値は、"`conjunction`"、"`disjunction`"、"`unit`" のいずれかです。 + +## 例 + +## resolvedOptions の使用 + +```js +const deListFormatter = new Intl.ListFormat("de-DE", { style: "short" }); + +const usedOptions = de.resolvedOptions(); +console.log(usedOptions.locale); // "de-DE" +console.log(usedOptions.style); // "short" +console.log(usedOptions.type); // "conjunction" (the default value) +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.ListFormat")}} +- {{jsxref("Intl/NumberFormat/resolvedOptions", + "Intl.NumberFormat.prototype.resolvedOptions()")}} +- {{jsxref("Intl/Collator/resolvedOptions", + "Intl.Collator.prototype.resolvedOptions()")}} +- {{jsxref("Intl/DateTimeFormat/resolvedOptions", + "Intl.DateTimeFormat.prototype.resolvedOptions()")}} +- {{jsxref("Intl/PluralRules/resolvedOptions", + "Intl.PluralRules.prototype.resolvedOptions()")}} -- cgit v1.2.3-54-g00ecf From 61d600f084b018ace88006b0eccf90a8aece63e4 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Tue, 31 Aug 2021 09:58:57 +0900 Subject: Global_Objects/Intl/Locale 以下のメソッドを更新 (#2200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - maximize(), minimize(), toString() のメソッドを更新 - 2021/08/22 時点の英語版に同期 --- .../global_objects/intl/locale/maximize/index.html | 77 ---------------------- .../global_objects/intl/locale/maximize/index.md | 68 +++++++++++++++++++ .../global_objects/intl/locale/minimize/index.html | 76 --------------------- .../global_objects/intl/locale/minimize/index.md | 66 +++++++++++++++++++ .../global_objects/intl/locale/tostring/index.html | 65 ------------------ .../global_objects/intl/locale/tostring/index.md | 58 ++++++++++++++++ 6 files changed, 192 insertions(+), 218 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.md delete mode 100644 files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html deleted file mode 100644 index 1d7cad466a..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.html +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Intl.Locale.prototype.maximize() -slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize -tags: - - Internationaliztion - - Intl - - JavaScript - - Method - - Prototype - - Reference - - メソッド - - 国際化 -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize ---- -
{{JSRef}}
- -

Intl.Locale.prototype.maximize() メソッドは、既存の値に基づいてロケールの言語、表記法、地域の最も可能性の近い値を取得します。

- -
{{EmbedInteractiveExample("pages/js/intl-locale-prototype-maximize.html")}}
- - - -

構文

- -
locale.maximize()
- -

返値

- -

{{jsxref("Locale", "Locale")}} インスタンスで、 baseName プロパティが、 Add Likely Subtags アルゴリズムが {{jsxref("Locale/baseName", "locale.baseName")}} に対して実行された結果になったものを返します。

- -

解説

- -

不完全な言語識別子をもとに、最も可能性の高いロケール言語識別子サブタグを識別できると便利な場合があります。 Add Likely Subtags アルゴリズムはこの機能を提供してくれます。例えば、言語識別子 "en" が与えられた場合、アルゴリズムは "en-Latn-US" を返すことになります。英語はラテン文字でしか書けませんし、世界最大の英語圏の国であるアメリカで使われている可能性が高いからです。この機能は、 maximize() メソッドを介して JavaScript プログラマーに提供されています。 maximize() は、言語識別子を構成する主要なサブタグのうち言語サブ、表記法、地域の各サブタグにのみ影響を与えます。ロケール識別子の "-u" の後にあるその他のサブタグは拡張サブタグと呼ばれ、 maximize() メソッドの影響を受けません。これらのサブタグの例としては、 {{jsxref("Locale/hourCycle", "Locale.hourCycle")}}, {{jsxref("Locale/calendar", "Locale.calendar")}}, {{jsxref("Locale/numeric", "Locale.numeric")}} などがあります。

- -

- -
let myLocale = new Intl.Locale("ja", {hourCycle: "h24", calendar: "gregory"});
-console.log(myLocale.baseName); // "ja" と表示
-console.log(myLocale.toString()); // "ja-u-ca-gregory-hc-h24" と表示
-let myLocMaximized = myLocale.maximize();
-
-// "ja-Jpan-JP"。 "Jpan" と "JP" タグが追加されます。
-// これは、日本語が主に漢字かな交じり文 (Jpan) で書かれ、また主に日本 (JP) で話されているためです。
-console.log(myLocMaximized.baseName);
-
-// "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示します。
-// なお、拡張タグ ("-u" 以降) はそのまま残ります。
-console.log(myLocMaximized.toString()); 
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.maximize')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.Locale.maximize")}}

-
- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.md b/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.md new file mode 100644 index 0000000000..aae9be3eca --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/maximize/index.md @@ -0,0 +1,68 @@ +--- +title: Intl.Locale.prototype.maximize() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize +tags: + - 国際化 + - Intl + - JavaScript + - Locale + - メソッド + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.Locale.maximize +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize +--- +{{JSRef}} + +**`Intl.Locale.prototype.maximize()`** メソッドは、既存の値に基づいてロケールの言語、表記法、地域の最も可能性の近い値を取得します。 + +{{EmbedInteractiveExample("pages/js/intl-locale-prototype-maximize.html")}} + + +## 構文 + +```js +maximize() +``` + +### 返値 + +{{jsxref("Intl/Locale", "Locale")}} インスタンスのうち、 `baseName` プロパティが [Add Likely Subtags](https://www.unicode.org/reports/tr35/#Likely_Subtags) アルゴリズムを _{{jsxref("Intl/Locale/baseName", "locale.baseName")}}_.に対して実行した結果になっているものを返します。 + +## 解説 + +不完全な言語識別子をもとに、最も可能性の高いロケール言語識別子サブタグを識別できると便利な場合があります。 Add Likely Subtags アルゴリズムはこの機能を提供してくれます。例えば、言語識別子 "en" が与えられた場合、アルゴリズムは "en-Latn-US" を返すことになります。英語はラテン文字でしか書けませんし、世界最大の英語圏の国であるアメリカで使われている可能性が高いからです。この機能は、 `maximize()` メソッドを介して JavaScript プログラマーに提供されています。 `maximize()` は、[言語識別子](https://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions)を構成する主要なサブタグのうち言語サブ、表記法、地域の各サブタグにのみ影響を与えます。ロケール識別子の "-u" の後にあるその他のサブタグは拡張サブタグと呼ばれ、 `maximize()` メソッドの影響を受けません。これらのサブタグの例としては、{{jsxref("Intl/Locale/hourCycle", "Locale.hourCycle")}}、{{jsxref("Intl/Locale/calendar", "Locale.calendar")}}、{{jsxref("Intl/Locale/numeric", "Locale.numeric")}} などがあります。

+ +## 例 + +### maximize の使用 + +```js +let myLocale = new Intl.Locale("ja", {hourCycle: "h24", calendar: "gregory"}); +console.log(myLocale.baseName); // "ja" と表示 +console.log(myLocale.toString()); // "ja-u-ca-gregory-hc-h24" と表示 +let myLocMaximized = myLocale.maximize(); + +// "ja-Jpan-JP"。 "Jpan" と "JP" タグが追加されます。 +// これは、日本語が主に漢字かな交じり文 (Jpan) で書かれ、また主に日本 (JP) で話されているためです。 +console.log(myLocMaximized.baseName); + +// "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示します。 +// なお、拡張タグ ("-u" 以降) はそのまま残ります。 +console.log(myLocMaximized.toString()); +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.Locale")}} +- {{jsxref("Intl/Locale/baseName", "Intl.Locale.baseName")}} +- [Unicode's Likely + Subtags spec](https://www.unicode.org/reports/tr35/#Likely_Subtags) diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html deleted file mode 100644 index b83e495348..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.html +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: Intl.Locale.prototype.minimize() -slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize -tags: - - Internationalization - - Intl - - JavaScript - - Method - - Prototype - - Reference - - 国際化 -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize ---- -
{{JSRef}}
- -

Intl.Locale.prototype.minimize() メソッドは、 {{jsxref("Locale/maximize", "Locale.maximize()")}} を呼び出したことで追加されるロケールに関する情報を削除しようとします。

- -
{{EmbedInteractiveExample("pages/js/intl-locale-prototype-minimize.html", "taller")}}
- - - -

構文

- -
locale.minimize()
- -

返値

- -

{{jsxref("Locale", "Locale")}} インスタンスで、 baseName プロパティが、 Remove Likely Subtags アルゴリズムが locale.baseName に対して実行された結果になったものを返します。

- -

解説

- -

このメソッドは {{jsxref("Locale/maximize", "maximize()")}} の逆の処理を行い、ロケールの言語識別子 (基本的には baseName の内容) から言語、文字体系、地域のサブタグをすべて削除します。これは、言語識別子の中に余分なサブタグがある場合に便利です。例えば "en-Latn" は "en" に簡略化できます。英語では "Latn" が書き言葉に使われる唯一の文字体系だからです。 minimize() が影響を与えるのは、言語識別子を構成する主要なサブタグである言語、文字体系、地域の各サブタグのみです。ロケール識別子の "-u" の後にあるその他のサブタグは拡張サブタグと呼ばれ、 minimize() メソッドの影響を受けません。これらのサブタグの例としては、 {{jsxref("Locale/hourCycle", "Locale.hourCycle")}}, {{jsxref("Locale/calendar", "Locale.calendar")}}, {{jsxref("Locale/numeric", "Locale.numeric")}} などがあります。

- -

- -
let myLocale = new Intl.Locale("ja-Jpan-JP", {hourCycle: "h24", calendar: "gregory"});
-console.log(myLocale.baseName); // "ja-Jpan-JP" と表示
-console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示
-
-let myLocMinimized = myLocale.minimize();
-
-// "ja" のみを表示します。日本語は主に漢字かな交じり文 (Jpan) で
-// 表記され、またほとんど日本で話されているためです。
-console.log(myLocMinimized.baseName);
-
-// "ja-u-ca-gregory-hc-h24" と表示します。
-// なお、拡張タグ ("-u" 以降) はそのまま残ります。
-console.log(myLocMinimized.toString());
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.minimize')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.Locale.minimize")}}

-
- -

関連情報

- -
    -
  • {{jsxref("Locale", "Intl.Locale")}}
  • -
  • {{jsxref("Locale/baseName", "Intl.Locale.baseName")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.md b/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.md new file mode 100644 index 0000000000..db7cd28fd1 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/minimize/index.md @@ -0,0 +1,66 @@ +--- +title: Intl.Locale.prototype.minimize() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize +tags: + - 国際化 + - Intl + - JavaScript + - メソッド + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.Locale.minimize +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize +--- +{{JSRef}} + +**`Intl.Locale.prototype.minimize()`** メソッドは、 {{jsxref("Intl/Locale/maximize", "Locale.maximize()")}} を呼び出したことで追加されるロケールに関する情報を削除しようとします。 + +{{EmbedInteractiveExample("pages/js/intl-locale-prototype-minimize.html", "taller")}} + + +## 構文 + +```js +minimize() +``` + +### 返値 + +{{jsxref("Intl/Locale", "Locale")}} インスタンスで、 `baseName` プロパティが、 [Remove Likely Subtags](https://www.unicode.org/reports/tr35/#Likely_Subtags) アルゴリズムを _{{jsxref("Intl/Locale/baseName", "locale.baseName")}}_ に対して実行された結果になったものを返します。 + +## 解説 + +このメソッドは {{jsxref("Intl/Locale/maximize", "maximize()")}} の逆の処理を行い、ロケールの言語識別子 (基本的には `baseName` の内容) から言語、表記法、地域のサブタグをすべて削除します。これは、言語識別子の中に余分なサブタグがある場合に便利です。例えば "en-Latn" は "en" に簡略化できます。英語では "Latn" が書き言葉に使われる唯一の表記法だからです。 `minimize()` が影響を与えるのは、[言語識別子](https://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions)を構成する主要なサブタグである言語、表記法、地域の各サブタグのみです。ロケール識別子の "-u" の後にあるその他のサブタグは拡張サブタグと呼ばれ、 `minimize()` メソッドの影響を受けません。これらのサブタグの例としては、{{jsxref("Intl/Locale/hourCycle", "Locale.hourCycle")}}、{{jsxref("Intl/Locale/calendar", "Locale.calendar")}}、{{jsxref("Intl/Locale/numeric", "Locale.numeric")}} などがあります。 + +## 例 + +### minimize の使用 + +```js +let myLocale = new Intl.Locale("ja-Jpan-JP", {hourCycle: "h24", calendar: "gregory"}); +console.log(myLocale.baseName); // "ja-Jpan-JP" と表示 +console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示 + +let myLocMinimized = myLocale.minimize(); + +// "ja" のみを表示します。日本語は主に漢字かな交じり文 (Jpan) で +// 表記され、またほとんど日本で話されているためです。 +console.log(myLocMinimized.baseName); + +// "ja-u-ca-gregory-hc-h24" と表示します。 +// なお、拡張タグ ("-u" 以降) はそのまま残ります。 +console.log(myLocMinimized.toString()); +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.Locale")}} +- {{jsxref("Intl/Locale/baseName", "Intl.Locale.baseName")}} diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html b/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html deleted file mode 100644 index 4fdc4acec8..0000000000 --- a/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.html +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: Intl.Locale.prototype.toString() -slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString -tags: - - Intl - - JavaScript - - Method - - Prototype - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString ---- -
{{JSRef}}
- -

Intl.Locale.prototype.toString() は、このロケールの完全なロケール識別子文字列を返します。

- -
{{EmbedInteractiveExample("pages/js/intl-locale-prototype-tostring.html")}}
- - - -

構文

- -
locale.toString()
- -

返値

- -

このロケールの Unicode ロケール識別子文字列です。

- -

解説

- -

Locale オブジェクトは、概念的な Unicode ロケール識別子を JavaScript で表現したものです。特定のロケールに関する情報 (言語、文字体系、カレンダーの種類など) を、ロケール識別子文字列で符号化することができます。これらのロケール識別子をより簡単に扱えるようにするために、 Locale オブジェクトが JavaScript に導入されました。 Locale オブジェクトの toString メソッドをコールすると、そのロケールの識別子文字列を返します。 toString メソッドを使用すると、 Locale のインスタンスが既存の Intl のコンストラクターへの引数ととして JSON におけるシリアライズにおいて、またはその他のコンテキストで正確な文字列表現が有用な場合に提供することができます。

- -

- -
let myLocale = new Intl.Locale("ja-Jpan-JP", {hourCycle: "h24", calendar: "gregory"});
-console.log(myLocale.baseName); // "ja-Jpan-JP" と表示
-console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示
-
- -

仕様書

- - - - - - - - - - - - -
仕様書
{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.toString')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Intl.Locale.toString")}}

-
- -

関連情報

- -
    -
  • {{jsxref("Locale", "Intl.Locale")}}
  • -
  • {{jsxref("Locale/baseName", "Intl.Locale.baseName")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.md b/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.md new file mode 100644 index 0000000000..f62794a64c --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/intl/locale/tostring/index.md @@ -0,0 +1,58 @@ +--- +title: Intl.Locale.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString +tags: + - Internationalization + - Intl + - JavaScript + - Locale + - Method + - Prototype + - Reference +browser-compat: javascript.builtins.Intl.Locale.toString +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/toString +--- +{{JSRef}} + +**`Intl.Locale.prototype.toString()`** は、このロケールの完全な[ロケール識別子文字列](https://www.unicode.org/reports/tr35/#Unicode_locale_identifier)を返します。 + +{{EmbedInteractiveExample("pages/js/intl-locale-prototype-tostring.html")}} + + + +## 構文 + +```js +toString() +``` + +### 返値 + +この*ロケール*の Unicode ロケール識別子文字列です。 + +## 解説 + +`Locale` オブジェクトは、概念的な Unicode ロケール識別子を JavaScript で表現したものです。特定のロケールに関する情報 (言語、表記法、カレンダーの種類など) を、ロケール識別子文字列で符号化することができます。これらのロケール識別子をより簡単に扱えるようにするために、 `Locale` オブジェクトが JavaScript に導入されました。 Locale オブジェクトの `toString` メソッドをコールすると、そのロケールの識別子文字列を返します。 `toString` メソッドを使用すると、 `Locale` のインスタンスが既存の `Intl` のコンストラクターへの引数ととして JSON におけるシリアライズにおいて、またはその他のコンテキストで正確な文字列表現が有用な場合に提供することができます。 + +## 例 + +### toString の使用 + +```js +let myLocale = new Intl.Locale("ja-Jpan-JP", {hourCycle: "h24", calendar: "gregory"}); +console.log(myLocale.baseName); // "ja-Jpan-JP" と表示 +console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示 +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{jsxref("Intl.Locale")}} +- {{jsxref("Intl/Locale/baseName", "Intl.Locale.baseName")}} -- cgit v1.2.3-54-g00ecf From 5773c96bd424f4956994d1493b6434a5e1c4e9ef Mon Sep 17 00:00:00 2001 From: Junsei Nagao <54606780+junseinagao@users.noreply.github.com> Date: Tue, 31 Aug 2021 13:18:48 +0900 Subject: 'Using Date.parse() の使用' -> 'Date.parse()の使用' (#2257) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/javascript/reference/global_objects/date/parse/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/date/parse/index.html b/files/ja/web/javascript/reference/global_objects/date/parse/index.html index ec4a46ca35..b666075816 100644 --- a/files/ja/web/javascript/reference/global_objects/date/parse/index.html +++ b/files/ja/web/javascript/reference/global_objects/date/parse/index.html @@ -107,7 +107,7 @@ Date.parse('foo-bar 2014');

-

Using Date.parse() の使用

+

Date.parse() の使用

以下の呼び出しはすべて 1546300800000 を返します。最初のものは ES5 によれば UTC 時刻を意味し、それ以外は ISO 日付仕様 (Z および +00:00) に従って UTC をタイムゾーンを指定しています。

-- cgit v1.2.3-54-g00ecf From b9d1f98e37d8b4055e2806ef08f94ab068b835ab Mon Sep 17 00:00:00 2001 From: Yoshiyuki Hisamatsu Date: Tue, 31 Aug 2021 13:18:58 +0900 Subject: Fix typo "グローバルグローバル変数" to "グローバル変数" (#2258) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change text "グローバルグローバル変数" to "グローバル変数" --- .../ja/web/javascript/reference/global_objects/asyncfunction/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/asyncfunction/index.html b/files/ja/web/javascript/reference/global_objects/asyncfunction/index.html index bc4359a60b..eaf1f2c2e9 100644 --- a/files/ja/web/javascript/reference/global_objects/asyncfunction/index.html +++ b/files/ja/web/javascript/reference/global_objects/asyncfunction/index.html @@ -39,7 +39,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/AsyncFunction

注: {{jsxref("Statements/async_function", "非同期関数", "", 1)}}が AsyncFunction コンストラクターによって生成された場合、生成コンテキストのクロージャは生成されません。常にグローバルスコープに生成されます。

-

実行すると、ローカル変数とグローバルグローバル変数にのみアクセスでき、 AsyncFunction コンストラクターが呼び出されたスコープの変数にはアクセスできません。

+

実行すると、ローカル変数とグローバル変数にのみアクセスでき、 AsyncFunction コンストラクターが呼び出されたスコープの変数にはアクセスできません。

これは、非同期関数式のコードで {{jsxref("Global_Objects/eval", "eval")}} を使用した場合とは異なります。

-- cgit v1.2.3-54-g00ecf From 46fbca1c6143a6e0dc3a3f7480cfda1e1f2d150f Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Wed, 1 Sep 2021 23:56:24 +0900 Subject: Global_Objects/WebAssembly/validate を更新 (#2208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化 - 2021/07/21 時点の英語版に同期 --- .../global_objects/webassembly/validate/index.html | 71 ---------------------- .../global_objects/webassembly/validate/index.md | 66 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 71 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/validate/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/validate/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/validate/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/validate/index.html deleted file mode 100644 index 14a9631831..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/validate/index.html +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: WebAssembly.validate() -slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate -translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate ---- -
{{JSRef}} {{SeeCompatTable}}
- -

WebAssembly.validate() 関数は WebAssembly バイナリコードを含む 型付き配列 をバリデーションし、バイト列が有効な wasm モジュール (true) か、そうでないか (false) を返します。

- -

構文

- -
WebAssembly.validate(bufferSource);
- -

パラメータ

- -
-
bufferSource
-
バリデーションする WebAssembly バイナリコードを含む 型付き配列 か ArrayBuffer 。
-
- -

戻り値

- -

有効な wasm モジュール (true) か、そうでないか (false) を示す boolean 値。

- -

例外

- -

bufferSource が 型付き配列 か ArrayBuffer でない場合、{{jsxref("TypeError")}} がスローされます。

- -

- -

以下の例 (validate.html の ソースコード と 動作例 をご確認ください) は .wasm モジュールをフェッチして型付き配列に変換します。次に、 validate() メソッドを使用してモジュールが有効かどうかをチェックします。

- -
fetch('simple.wasm').then(response =>
-  response.arrayBuffer()
-).then(function(bytes) {
-  var valid = WebAssembly.validate(bytes);
-  console.log("The given bytes are "
-    + (valid ? "" : "not ") + "a valid wasm module");
-});
-
- -

仕様

- - - - - - - - - - - - - - - - -
仕様策定状況コメント
{{SpecName('WebAssembly JS', '#webassemblyvalidate', 'validate()')}}{{Spec2('WebAssembly JS')}}初回ドラフト定義。
- -

ブラウザ実装状況

- -
{{Compat("javascript.builtins.WebAssembly.validate")}}
- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/validate/index.md b/files/ja/web/javascript/reference/global_objects/webassembly/validate/index.md new file mode 100644 index 0000000000..5f979a4411 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/webassembly/validate/index.md @@ -0,0 +1,66 @@ +--- +title: WebAssembly.validate() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate +tags: + - API + - JavaScript + - Method + - Object + - Reference + - WebAssembly + - validate +browser-compat: javascript.builtins.WebAssembly.validate +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/validate +--- +{{JSRef}} + +**`WebAssembly.validate()`** 関数は WebAssembly バイナリーコードの[型付き配列](/ja/docs/Web/JavaScript/Typed_arrays)を検証し、そのバイト列が有効な wasm モジュールか (`true`)、そうでないか (`false`) を返します。 + +## 構文 + +```js +WebAssembly.validate(bufferSource) +``` + +### 引数 + +- `bufferSource` + - : 検証する WebAssembly バイナリーコードを含む[型付き配列](/ja/docs/Web/JavaScript/Typed_arrays)または [`ArrayBuffer`](/ja/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)。 + +### 返値 + +有効な wasm モジュールであるか (`true`)、そうでないか (`false`) を示す論理値です。 + +### 例外 + +`bufferSource` が[型付き配列](/ja/docs/Web/JavaScript/Typed_arrays)または [`ArrayBuffer`](/ja/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) でない場合、{{jsxref("TypeError")}} が発生します。 + +## 例 + +### validate の使用 + +以下の例 (`validate.html` の[ソースコード](https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/validate.html)と[動作例](https://mdn.github.io/webassembly-examples/js-api-examples/validate.html) をご確認ください) は .wasm モジュールを読み取って型付き配列に変換します。次に、 `validate()` メソッドを使用してモジュールが有効かどうかをチェックします。

+ +```js +fetch('simple.wasm').then(response => +  response.arrayBuffer() +).then(function(bytes) { +  var valid = WebAssembly.validate(bytes); +  console.log("The given bytes are " + + (valid ? "" : "not ") + "a valid wasm module"); +}); +``` + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [WebAssembly](/ja/docs/WebAssembly) 概要ページ +- [WebAssembly の概念](/ja/docs/WebAssembly/Concepts) +- [WebAssembly JavaScript API の使用](/ja/docs/WebAssembly/Using_the_JavaScript_API) -- cgit v1.2.3-54-g00ecf From 7120a5bda383e235f7e4186fc3312ddb4c822db4 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Wed, 1 Sep 2021 23:56:41 +0900 Subject: Global_Objects/WebAssembly/instantiateStreaming を更新 (#2209) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markdown化 - 2021/07/21 時点の英語版に同期 --- .../webassembly/instantiatestreaming/index.html | 83 ---------------------- .../webassembly/instantiatestreaming/index.md | 73 +++++++++++++++++++ 2 files changed, 73 insertions(+), 83 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.html b/files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.html deleted file mode 100644 index fb3ba701c1..0000000000 --- a/files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.html +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: WebAssembly.instantiateStreaming() -slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming -translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming ---- -
{{JSRef}} {{SeeCompatTable}}
- -

WebAssembly.instantiateStreaming() 関数はソースのストリームから直接 WebAssembly モジュールをコンパイルしてインスタンス化します。

- -

構文

- -
Promise<ResultObject> WebAssembly.instantiateStreaming(source, importObject);
- -

パラメータ

- -
-
source
-
コンパイルしてインスタンス化する .wasm モジュールのソースを表す {{domxref("Response")}} オブジェクトか、それをfulfillするプロミス。
-
importObject {{optional_inline}}
-
関数や {{jsxref("WebAssembly.Module")}} オブジェクトなどの新しく生成される Instance にインポートされる値を持つオブジェクト。モジュール内で宣言されたインポートそれぞれに対応するプロパティが存在する必要があります。そうでない場合、{{jsxref("WebAssembly.LinkError")}} がスローされます。
-
- -

戻り値

- -

解決時に次の2つのフィールドを持つ ResultObject を渡す Promise:

- - - -

例外

- -
    -
  • いずれかのパラメータが正しい型、または構造でない場合、{{jsxref("TypeError")}} がスローされます。
  • -
  • 失敗した場合、プロミスは失敗の原因に応じて {{jsxref("WebAssembly.CompileError")}}、{{jsxref("WebAssembly.LinkError")}} または {{jsxref("WebAssembly.RuntimeError")}} を持って棄却されます。
  • -
- -

- -

次の例 (Github上のデモ instantiate-streaming.html と、 動作例 を参照してください) では、ソースから .wasm モジュールを直接コンパイルしてインスタンス化しています。プロミスは ResultObject で fulfill されます。instantiateStreaming()  関数は {{domxref("Response")}} オブジェクトを渡すプロミスを受け取るので、直接 {{domxref("WindowOrWorkerGlobalScope.fetch()")}} 呼び出し結果を渡すことができます。

- -
var importObject = { imports: { imported_func: arg => console.log(arg) } };
-
-WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject)
-.then(obj => obj.instance.exports.exported_func());
- -

最後に ResultObject が持つ instance メンバーにアクセスして、エクスポートされた関数を実行しています。

- -

仕様

- - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('WebAssembly Embedding', '#webassemblyinstantiatestreaming', 'instantiateStreaming()')}}{{Spec2('WebAssembly Embedding')}}初回ドラフト定義
- -

ブラウザ実装状況

- -
- - -

{{Compat("javascript.builtins.WebAssembly.instantiateStreaming")}}

-
- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.md b/files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.md new file mode 100644 index 0000000000..d157a5c651 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/webassembly/instantiatestreaming/index.md @@ -0,0 +1,73 @@ +--- +title: WebAssembly.instantiateStreaming() +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming +tags: + - API + - JavaScript + - Method + - Object + - Reference + - WebAssembly + - instantiate + - instantiateStreaming + - streaming +browser-compat: javascript.builtins.WebAssembly.instantiateStreaming +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming +--- +{{JSRef}} + +**`WebAssembly.instantiateStreaming()`** 関数は、ソースのストリームから直接 WebAssembly モジュールをコンパイルしてインスタンス化します。これは、 wasm コードをロードするための最も効率的で最適な方法です。 + +```js +WebAssembly.instantiateStreaming(source, importObject) +``` + +### 引数 + +- _source_ + - : [`Response`](/ja/docs/Web/API/Response "Response は Fetch API のインターフェースで、リクエストに対するレスポンスを表します。") オブジェクト、またはそれで解決するプロミスで、コンパイルしてインスタンス化する .wasm モジュールのソースを表します。 +- _importObject_ {{optional_inline}} + - : 関数や {{jsxref("WebAssembly.Memory")}} オブジェクトなど、新しく生成される `Instance` にインポートされる値を持つオブジェクト。コンパイルされたモジュールの宣言されたインポートそれぞれに対応するプロパティが存在する必要があります。そうでない場合、[`WebAssembly.LinkError`](/ja/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError) が発生します。 + +### 返値 + +`Promise` で、次の 2 つのフィールドを持つ `ResultObject` で解決します。 + +- `module`: コンパイルされた {{jsxref("WebAssembly.Module")}} オブジェクト。この `Module` は再度インスタンス化することや、[postMessage()](/ja/docs/Web/API/Worker/postMessage) 経由で共有することができます。 +- `instance`: {{jsxref("WebAssembly.Instance")}} オブジェクトで、すべての[エクスポートされた WebAssembly 関数](/ja/docs/WebAssembly/Exported_functions)を含みます。 + +### 例外 + +- いずれかの引数が正しい型または構造でない場合、{{jsxref("TypeError")}} が発生します。 +- 失敗した場合、プロミスは失敗の原因に応じて {{jsxref("WebAssembly.CompileError")}}、{{jsxref("WebAssembly.LinkError")}}、{{jsxref("WebAssembly.RuntimeError")}} をもって拒否されます。 + +## 例 + +### ストリーミングのインスタンス化 + +次の例 (Github上のデモ [instantiate-streaming.html](https://github.com/mdn/webassembly-examples/blob/master/js-api-examples/instantiate-streaming.html) と、[動作例](https://mdn.github.io/webassembly-examples/js-api-examples/instantiate-streaming.html)を参照してください) では、ソースから .wasm モジュールを直接コンパイルしてインスタンス化しています。プロミスは `ResultObject` で充足されます。`instantiateStreaming()` 関数は [`Response`](/ja/docs/Web/API/Response "Response は Fetch API のインターフェースで、リクエストに対するレスポンスを表します。") オブジェクトを渡すプロミスを受け取るので、直接 [`WindowOrWorkerGlobalScope.fetch()`](/ja/docs/Web/API/WindowOrWorkerGlobalScope/fetch "WindowOrWorkerGlobalScope ミックスインの fetch() メソッドは、ネットワークからリソースをフェッチするプロセスを開始し、レスポンスが利用可能になると履行される約束を返します。") 呼び出し結果を渡すことができます。 + +```js +var importObject = { imports: { imported_func: arg => console.log(arg) } }; + +WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject) +.then(obj => obj.instance.exports.exported_func()); +``` + +最後に `ResultObject` が持つ instance メンバーにアクセスして、エクスポートされた関数を実行しています。 + +> **Note:** これを動作するようにするには、サーバが `.wasm` ファイルを `application/wasm` の MIME タイプで返す必要があります。 + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [WebAssembly](/ja/docs/WebAssembly) 概要ページ +- [WebAssembly の概念](/ja/docs/WebAssembly/Concepts) +- [WebAssembly JavaScript API の使用](/ja/docs/WebAssembly/Using_the_JavaScript_API) -- cgit v1.2.3-54-g00ecf From 86a2565c8c750af5d04a4924308f4a9e280fcaa5 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Wed, 1 Sep 2021 23:56:58 +0900 Subject: Web/JavaScript/Reference/Global_Objects を更新 (#2216) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 2021/07/21 時点の英語版に同期 --- .../javascript/reference/global_objects/index.html | 210 --------------------- .../javascript/reference/global_objects/index.md | 170 +++++++++++++++++ 2 files changed, 170 insertions(+), 210 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/index.md (limited to 'files/ja/web/javascript/reference/global_objects') diff --git a/files/ja/web/javascript/reference/global_objects/index.html b/files/ja/web/javascript/reference/global_objects/index.html deleted file mode 100644 index 44c08eeb57..0000000000 --- a/files/ja/web/javascript/reference/global_objects/index.html +++ /dev/null @@ -1,210 +0,0 @@ ---- -title: 標準組込みオブジェクト -slug: Web/JavaScript/Reference/Global_Objects -tags: - - JavaScript - - Landing page - - Overview - - Reference -translation_of: Web/JavaScript/Reference/Global_Objects ---- -

{{JSSidebar("Objects")}}

- -

本章では JavaScript の標準組込みオブジェクトについて、それらのメソッドやプロパティと共にすべて文書化しています。

- -

ここでいう「グローバルオブジェクト (global objects)」 (または標準組込みオブジェクト) という用語をグローバルオブジェクト (the global object) と混同しないでください。ここで、『グローバルオブジェクト』はグローバルスコープにあるオブジェクトを指します。 (訳注: 日本語では複数形や the による区別ができないため、ここでは後者の the global object を『グローバルオブジェクト』と表記して区別します。)

- -

後者の『グローバルオブジェクト』自体は、グローバルスコープ中で {{JSxRef("Operators/this", "this")}} 演算子を使ってアクセスすることができます。実際、グローバルスコープは『グローバルオブジェクト』 (継承されたプロパティがあればそれらも含む) のプロパティから構成されています

- -

グローバルスコープ内のその他のオブジェクトは、ユーザースクリプトによって作られるか、あるいはホストアプリによって提供されます。ブラウザー上で提供されている利用可能なオブジェクトについては、API リファレンス で文書化されています。

- - - -

DOM と中核の JavaScript との違いについての詳しい情報は、JavaScript 技術概説をご覧ください。

- -

標準オブジェクト (カテゴリ別)

- -

値プロパティ

- -

これらのグローバルプロパティは、単なる値を返します。これらはプロパティもメソッドも持ちません。

- -
    -
  • {{JSxRef("Infinity")}}
  • -
  • {{JSxRef("NaN")}}
  • -
  • {{JSxRef("undefined")}}
  • -
  • {{JSxRef("globalThis")}}
  • -
- -

関数プロパティ

- -

これらのグローバル関数 (オブジェクト上ではなくグローバルに呼ばれる関数) は、呼び出し元に直接結果を返します。

- -
-
    -
  • {{JSxRef("Global_Objects/eval", "eval()")}}
  • -
  • {{Non-Standard_Inline}} {{JSxRef("Global_Objects/uneval", "uneval()")}} 
  • -
  • {{JSxRef("Global_Objects/isFinite", "isFinite()")}}
  • -
  • {{JSxRef("Global_Objects/isNaN", "isNaN()")}}
  • -
  • {{JSxRef("Global_Objects/parseFloat", "parseFloat()")}}
  • -
  • {{JSxRef("Global_Objects/parseInt", "parseInt()")}}
  • -
  • {{JSxRef("Global_Objects/encodeURI", "encodeURI()")}}
  • -
  • {{JSxRef("Global_Objects/encodeURIComponent", "encodeURIComponent()")}}
  • -
  • {{JSxRef("Global_Objects/decodeURI", "decodeURI()")}}
  • -
  • {{JSxRef("Global_Objects/decodeURIComponent", "decodeURIComponent()")}}
  • -
  • Deprecated -
      -
    • {{deprecated_inline}} {{JSxRef("Global_Objects/escape", "escape()")}}
    • -
    • {{deprecated_inline}} {{JSxRef("Global_Objects/unescape", "unescape()")}}
    • -
    -
  • -
-
- -

基本オブジェクト

- -

これらは、他のすべてのオブジェクトの基礎となる、主要な基本オブジェクトです。これらには、一般的なオブジェクト、関数、そしてエラーを表すオブジェクトが含まれます。

- -
    -
  • {{JSxRef("Object")}}
  • -
  • {{JSxRef("Function")}}
  • -
  • {{JSxRef("Boolean")}}
  • -
  • {{JSxRef("Symbol")}}
  • -
- -

エラーオブジェクト

- -

エラーオブジェクトは基本オブジェクトの特殊型です。これらのオブジェクトには、基本的な {{JSxRef("Error")}} 型の他に、いくつかの特殊なエラー型があります。

- -
-
    -
  • {{JSxRef("Error")}}
  • -
  • {{Experimental_Inline}} {{JSxRef("AggregateError")}} 
  • -
  • {{JSxRef("EvalError")}}
  • -
  • {{JSxRef("InternalError")}}
  • -
  • {{JSxRef("RangeError")}}
  • -
  • {{JSxRef("ReferenceError")}}
  • -
  • {{JSxRef("SyntaxError")}}
  • -
  • {{JSxRef("TypeError")}}
  • -
  • {{JSxRef("URIError")}}
  • -
-
- -

数と日付

- -

これらは数、日付、数学計算を表す基本的なオブジェクトです。

- -
    -
  • {{JSxRef("Number")}}
  • -
  • {{JSxRef("BigInt")}}
  • -
  • {{JSxRef("Math")}}
  • -
  • {{JSxRef("Date")}}
  • -
- -

テキスト処理

- -

これらのオブジェクトは、文字列表現および文字列操作をサポートします。

- -
    -
  • {{JSxRef("String")}}
  • -
  • {{JSxRef("RegExp")}}
  • -
- -

索引付きコレクション

- -

これらのオブジェクトは、インデックス値で順序付けされたデータのコレクションを表します。これには、(型付けされた) 配列や配列に似た構造体も含まれます。

- -
-
    -
  • {{JSxRef("Array")}}
  • -
  • {{JSxRef("Int8Array")}}
  • -
  • {{JSxRef("Uint8Array")}}
  • -
  • {{JSxRef("Uint8ClampedArray")}}
  • -
  • {{JSxRef("Int16Array")}}
  • -
  • {{JSxRef("Uint16Array")}}
  • -
  • {{JSxRef("Int32Array")}}
  • -
  • {{JSxRef("Uint32Array")}}
  • -
  • {{JSxRef("Float32Array")}}
  • -
  • {{JSxRef("Float64Array")}}
  • -
  • {{JSxRef("BigInt64Array")}}
  • -
  • {{JSxRef("BigUint64Array")}}
  • -
-
- -

キー付きコレクション

- -

これらのオブジェクトは、キーを使ったコレクションを表します。これらは、挿入順に反復可能な要素で構成されています。

- -
    -
  • {{JSxRef("Map")}}
  • -
  • {{JSxRef("Set")}}
  • -
  • {{JSxRef("WeakMap")}}
  • -
  • {{JSxRef("WeakSet")}}
  • -
- -

構造化データ

- -

これらのオブジェクトは、構造化データバッファおよび JavaScript Object Notation (JSON) を用いて書かれたデータを表現、操作します。

- -
    -
  • {{JSxRef("ArrayBuffer")}}
  • -
  • {{JSxRef("SharedArrayBuffer")}}
  • -
  • {{JSxRef("Atomics")}}
  • -
  • {{JSxRef("DataView")}}
  • -
  • {{JSxRef("JSON")}}
  • -
- -

制御抽象化オブジェクト

- -

制御抽象化オブジェクトは、特に非同期のコードを構造化するために役立ちます (例えば深く入り組んだコールバックを使用しないなど)。

- -
    -
  • {{JSxRef("Promise")}}
  • -
  • {{JSxRef("Generator")}}
  • -
  • {{JSxRef("GeneratorFunction")}}
  • -
  • {{JSxRef("AsyncFunction")}}
  • -
- -

リフレクション

- -
    -
  • {{JSxRef("Reflect")}}
  • -
  • {{JSxRef("Proxy")}}
  • -
- -

国際化

- -

ECMAScript コアに追加された言語の扱いに影響する機能です。

- -
-
    -
  • {{JSxRef("Intl")}}
  • -
  • {{JSxRef("Global_Objects/Collator", "Intl.Collator")}}
  • -
  • {{JSxRef("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}}
  • -
  • {{JSxRef("Global_Objects/ListFormat", "Intl.ListFormat")}}
  • -
  • {{JSxRef("Global_Objects/NumberFormat", "Intl.NumberFormat")}}
  • -
  • {{JSxRef("Global_Objects/PluralRules", "Intl.PluralRules")}}
  • -
  • {{JSxRef("Global_Objects/RelativeTimeFormat", "Intl.RelativeTimeFormat")}}
  • -
  • {{JSxRef("Global_Objects/Locale", "Intl.Locale")}}
  • -
-
- -

WebAssembly

- -
-
    -
  • {{JSxRef("WebAssembly")}}
  • -
  • {{JSxRef("WebAssembly.Module")}}
  • -
  • {{JSxRef("WebAssembly.Instance")}}
  • -
  • {{JSxRef("WebAssembly.Memory")}}
  • -
  • {{JSxRef("WebAssembly.Table")}}
  • -
  • {{JSxRef("WebAssembly.CompileError")}}
  • -
  • {{JSxRef("WebAssembly.LinkError")}}
  • -
  • {{JSxRef("WebAssembly.RuntimeError")}}
  • -
-
- -

その他

- -
    -
  • {{JSxRef("Functions/arguments", "arguments")}}
  • -
diff --git a/files/ja/web/javascript/reference/global_objects/index.md b/files/ja/web/javascript/reference/global_objects/index.md new file mode 100644 index 0000000000..196e993730 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/index.md @@ -0,0 +1,170 @@ +--- +title: 標準組み込みオブジェクト +slug: Web/JavaScript/Reference/Global_Objects +tags: + - JavaScript + - Landing page + - Overview + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects +--- +{{JSSidebar("Objects")}} + +本章では JavaScript の標準組み込みオブジェクトについて、それらのメソッドやプロパティと共にすべて文書化しています。 + +ここでいう「グローバルオブジェクト (global objects)」 (または標準組み込みオブジェクト) という用語を**グローバルオブジェクト** (the global object) と混同しないでください。ここで、『グローバルオブジェクト』は**グローバルスコープにあるオブジェクト**を指します。 (訳注: 日本語では複数形や the による区別ができないため、ここでは後者の **the global object** を『グローバルオブジェクト』と表記して区別します。) + +後者の『グローバルオブジェクト』自体は、グローバルスコープ中で {{JSxRef("Operators/this", "this")}} 演算子を使ってアクセスすることができます。実際、グローバルスコープは『グローバルオブジェクト』のプロパティと、もしあれば継承されたプロパティから**構成されています**。 + +グローバルスコープ内のその他のオブジェクトは、[ユーザースクリプトによって作られたり](/ja/docs/Web/JavaScript/Guide/Working_with_Objects#creating_new_objects)、ホストアプリケーションによって提供されたりします。ブラウザー上で提供されている利用可能なオブジェクトについては、[API リファレンス](/ja/docs/Web/API)で文書化されています。 + +[DOM](/en-US/docs/Web/API/Document_Object_Model) と中核の [JavaScript](/en-US/docs/Web/JavaScript) との違いについての詳しい情報は、[JavaScript 技術概説](/en-US/docs/Web/JavaScript/JavaScript_technologies_overview)をご覧ください。 + +## 標準オブジェクト (カテゴリー別) + +### 値プロパティ + +これらのグローバルプロパティは、単なる値を返します。プロパティもメソッドも持ちません。 + +- {{JSxRef("Infinity")}} +- {{JSxRef("NaN")}} +- {{JSxRef("undefined")}} +- {{JSxRef("globalThis")}} + +### 関数プロパティ + +これらのグローバル関数 (オブジェクト上ではなくグローバルに呼ばれる関数) は、呼び出し元に直接結果を返します。 + +- {{JSxRef("Global_Objects/eval", "eval()")}} +- {{Non-Standard_Inline}} {{JSxRef("Global_Objects/uneval", "uneval()")}} +- {{JSxRef("Global_Objects/isFinite", "isFinite()")}} +- {{JSxRef("Global_Objects/isNaN", "isNaN()")}} +- {{JSxRef("Global_Objects/parseFloat", "parseFloat()")}} +- {{JSxRef("Global_Objects/parseInt", "parseInt()")}} +- {{JSxRef("Global_Objects/encodeURI", "encodeURI()")}} +- {{JSxRef("Global_Objects/encodeURIComponent", "encodeURIComponent()")}} +- {{JSxRef("Global_Objects/decodeURI", "decodeURI()")}} +- {{JSxRef("Global_Objects/decodeURIComponent", "decodeURIComponent()")}} +- **非推奨** + + - {{Deprecated_Inline}} {{JSxRef("Global_Objects/escape", "escape()")}} + - {{Deprecated_Inline}} {{JSxRef("Global_Objects/unescape", "unescape()")}} + +### 基本オブジェクト + +他のすべてのオブジェクトの基礎となる、主要な基本オブジェクトです。一般的なオブジェクト、関数、そしてエラーを表すオブジェクトが含まれます。 + +- {{JSxRef("Object")}} +- {{JSxRef("Function")}} +- {{JSxRef("Boolean")}} +- {{JSxRef("Symbol")}} + +### エラーオブジェクト + +エラーオブジェクトは基本オブジェクトの特殊型です。これらのオブジェクトには、基本的な {{JSxRef("Error")}} 型の他に、いくつかの特殊なエラー型があります。 + +- {{JSxRef("Error")}} +- {{JSxRef("AggregateError")}} +- {{JSxRef("EvalError")}} +- {{JSxRef("InternalError")}} +- {{JSxRef("RangeError")}} +- {{JSxRef("ReferenceError")}} +- {{JSxRef("SyntaxError")}} +- {{JSxRef("TypeError")}} +- {{JSxRef("URIError")}} + +### 数値と日付 + +数値、日付、数学計算を表す基本的なオブジェクトです。 + +- {{JSxRef("Number")}} +- {{JSxRef("BigInt")}} +- {{JSxRef("Math")}} +- {{JSxRef("Date")}} + +### テキスト処理 + +これらのオブジェクトは、文字列を表したりその操作をサポートしたりします。 + +- {{JSxRef("String")}} +- {{JSxRef("RegExp")}} + +

索引付きコレクション

+ +これらのオブジェクトは、インデックス値で順序付けされたデータのコレクションを表します。これには、(型付けされた) 配列や配列に似た構造体も含まれます。 + +- {{JSxRef("Array")}} +- {{JSxRef("Int8Array")}} +- {{JSxRef("Uint8Array")}} +- {{JSxRef("Uint8ClampedArray")}} +- {{JSxRef("Int16Array")}} +- {{JSxRef("Uint16Array")}} +- {{JSxRef("Int32Array")}} +- {{JSxRef("Uint32Array")}} +- {{JSxRef("Float32Array")}} +- {{JSxRef("Float64Array")}} +- {{JSxRef("BigInt64Array")}} +- {{JSxRef("BigUint64Array")}} + +### キー付きコレクション + +これらのオブジェクトは、キーを使ったコレクションを表します。反復可能なコレクション ({{JSxRef("Map")}} と {{JSxRef("Set")}}) は挿入順に容易に反復処理することができます。 + +- {{JSxRef("Map")}} +- {{JSxRef("Set")}} +- {{JSxRef("WeakMap")}} +- {{JSxRef("WeakSet")}} + +### 構造化データ + +これらのオブジェクトは、構造化データバッファおよび JavaScript Object Notation (JSON) を用いて書かれたデータを表現、操作します。 + +- {{JSxRef("ArrayBuffer")}} +- {{JSxRef("SharedArrayBuffer")}} +- {{JSxRef("Atomics")}} +- {{JSxRef("DataView")}} +- {{JSxRef("JSON")}} + +### 制御抽象化オブジェクト + +制御抽象化オブジェクトは、特に非同期のコードを (例えば深く入り組んだコールバックを使用せずに) 構造化するのに役立ちます。 + +- {{JSxRef("Promise")}} +- {{JSxRef("Generator")}} +- {{JSxRef("GeneratorFunction")}} +- {{JSxRef("AsyncFunction")}} +- {{JSxRef("Global_Objects/AsyncGenerator", "AsyncGenerator")}} +- {{JSxRef("Global_Objects/AsyncGeneratorFunction", "AsyncGeneratorFunction")}} + +### リフレクション + +- {{JSxRef("Reflect")}} +- {{JSxRef("Proxy")}} + +### 国際化 + +中核の ECMAScript に言語に固有の機能を追加するものです。 + +- {{JSxRef("Intl")}} +- {{JSxRef("Global_Objects/Intl/Collator", "Intl.Collator")}} +- {{JSxRef("Global_Objects/Intl/DateTimeFormat", "Intl.DateTimeFormat")}} +- {{JSxRef("Global_Objects/Intl/ListFormat", "Intl.ListFormat")}} +- {{JSxRef("Global_Objects/Intl/NumberFormat", "Intl.NumberFormat")}} +- {{JSxRef("Global_Objects/Intl/PluralRules", "Intl.PluralRules")}} +- {{JSxRef("Global_Objects/Intl/RelativeTimeFormat", "Intl.RelativeTimeFormat")}} +- {{JSxRef("Global_Objects/Intl/Locale", "Intl.Locale")}} + +### WebAssembly + +- {{JSxRef("WebAssembly")}} +- {{JSxRef("WebAssembly.Module")}} +- {{JSxRef("WebAssembly.Instance")}} +- {{JSxRef("WebAssembly.Memory")}} +- {{JSxRef("WebAssembly.Table")}} +- {{JSxRef("WebAssembly.CompileError")}} +- {{JSxRef("WebAssembly.LinkError")}} +- {{JSxRef("WebAssembly.RuntimeError")}} + +### その他 + +- {{JSxRef("Functions/arguments", "arguments")}} -- cgit v1.2.3-54-g00ecf