From 6ef1fa4618e08426b874529619a66adbd3d1fcf0 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:07:59 +0100 Subject: unslug ja: move --- .../reference/global_objects/escape/index.html | 34 +++ .../global_objects/intl/datetimeformat/index.html | 88 ++++++ .../reference/global_objects/json/index.html | 95 +++++++ .../global_objects/string/lastindexof/index.html | 18 ++ .../reference/global_objects/unescape/index.html | 34 +++ .../global_objects/webassembly/instance/index.html | 64 +++++ .../global_objects/webassembly/memory/index.html | 71 +++++ .../global_objects/webassembly/table/index.html | 75 ++++++ .../reference/lexical_grammar/index.html | 89 +++++++ .../web/javascript/reference/operators/index.html | 232 ++++++++++++++++ .../reference/operators/yield/index.html | 7 + .../index.html | 295 +++++++++++++++++++++ 12 files changed, 1102 insertions(+) create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/escape/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/intl/datetimeformat/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/json/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/string/lastindexof/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/unescape/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/webassembly/instance/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/webassembly/memory/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/global_objects/webassembly/table/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/lexical_grammar/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/operators/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/operators/yield/index.html create mode 100644 files/ja/conflicting/web/javascript/reference/operators_f71733c8e7001a29c3ec40d8522a4aca/index.html (limited to 'files/ja/conflicting/web/javascript/reference') diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/escape/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/escape/index.html new file mode 100644 index 0000000000..48ab4cab3b --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/escape/index.html @@ -0,0 +1,34 @@ +--- +title: window.escape +slug: Web/API/Window/escape +tags: + - DOM + - DOM_0 + - Gecko + - Gecko DOM Reference + - Window +translation_of: Web/JavaScript/Reference/Global_Objects/escape +translation_of_original: Web/API/Window.escape +--- +
+ {{ApiRef}}
+

概要

+

文字列をエンコードし、16 進エスケープシーケンスで表された特定の文字に置換します。

+

構文

+
escaped = escape(regular);
+
+ +

+
alert( escape("http://www.cnn.com") ); // 表示結果: http%3A//www.cnn.com
+
+

注記

+

escape() メソッドは、特別な文字(通常のテキストや数字ではない文字)を 16 進文字にエンコードします。これは、特に、クッキーの値を設定するために必要となります。また、GET リクエストや AJAX GET/POST リクエストの URL で + + name=value + のような組のデータを渡すときにも役立ちます。

+

{{domxref("window.unescape")}} 、encodeURIComponent も参照してください。

+

仕様

+

{{DOM0}} 但し、ECMA-262 の非標準化セクションで言及されています。

diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/intl/datetimeformat/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/intl/datetimeformat/index.html new file mode 100644 index 0000000000..5705852c36 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/intl/datetimeformat/index.html @@ -0,0 +1,88 @@ +--- +title: Intl.DateTimeFormat.prototype +slug: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/prototype +tags: + - DateTimeFormat + - Internationalization + - JavaScript + - Property + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat +translation_of_original: Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/prototype +--- +
{{JSRef}}
+ +

Intl.DateTimeFormat.prototype プロパティは、 {{jsxref("Global_Objects/DateTimeFormat", "Intl.DateTimeFormat")}} コンストラクターに対するプロトタイプオブジェクトを表します。

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

解説

+ +

Intl.DateTimeFormat インスタンスの解説については {{jsxref("DateTimeFormat")}} を確認して下さい。

+ +

{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} インスタンスは Intl.DateTimeFormat.prototype から継承します。プロトタイプオブジェクトへの変更はすべての {{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} インスタンスによって継承されます。

+ +

プロパティ

+ +
+
Intl.DateTimeFormat.prototype.constructor
+
{{jsxref("DateTimeFormat", "Intl.DateTimeFormat")}} への参照です。
+
+ +

メソッド

+ +
+
{{jsxref("DateTimeFormat.format", "Intl.DateTimeFormat.prototype.format()")}}
+
ロケールおよびこの {{jsxref("DateTimeFormat", "DateTimeFormat")}} オブジェクトの書式化オプションに則って日付を書式化するゲッター関数です。
+
{{jsxref("DateTimeFormat.formatToParts", "Intl.DateTimeFormat.prototype.formatToParts()")}}
+
Returns an {{jsxref("Array")}} of objects representing the date string in parts that can be used for custom locale-aware formatting.
+
{{jsxref("DateTimeFormat.resolvedOptions", "Intl.DateTimeFormat.prototype.resolvedOptions()")}}
+
ローケルを反映しているプロパティとオブジェクトの初期化中に計算されたオプションをもった新しいオブジェクトを返します。
+
{{jsxref("DateTimeFormat.formatRange", "Intl.DateTimeFormat.prototype.formatRange()")}}
+
This method receives two Dates and formats the date range in the most concise way based on the locale and options provided when instantiating {{jsxref("DateTimeFormat", "DateTimeFormat")}}.
+
{{jsxref("DateTimeFormat.formatRangeToParts", "Intl.DateTimeFormat.prototype.formatRangeToParts()")}}
+
This method receives two Dates and returns an Array of objects containing the locale-specific tokens representing each part of the formatted date range.
+
+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('ES Int Draft', '#sec-Intl.DateTimeFormat.prototype', 'Intl.DateTimeFormat.prototype')}}{{Spec2('ES Int Draft')}}
{{SpecName('ES Int 2.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}{{Spec2('ES Int 2.0')}}
{{SpecName('ES Int 1.0', '#sec-12.2.1', 'Intl.DateTimeFormat.prototype')}}{{Spec2('ES Int 1.0')}}初回定義
+ +

ブラウザーの互換性

+ +
+ + +

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

+
+ +

関連情報

+ + diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/json/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/json/index.html new file mode 100644 index 0000000000..a4f38307ea --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/json/index.html @@ -0,0 +1,95 @@ +--- +title: ネイティブ JSON を使う +slug: Using_native_JSON +translation_of: Web/JavaScript/Reference/Global_Objects/JSON +translation_of_original: Web/JavaScript/Guide/Using_native_JSON +--- +
{{gecko_minversion_header("1.9.1")}}
+ +

この文書では、 Gecko 1.9.1 で追加された ECMAScript 5 互換のネイティブ JSON オブジェクトについて説明します。以前のバージョンの Firefox で JSON を扱う際の基本的な情報については、JSON のページをご覧下さい。

+ +

ネイティブ JSON オブジェクトは 2 つの重要なメソッドをもっています。JSON.parse() メソッドは JSON 文字列をパースし、 JavaScript のオブジェクトに変換します。JSON.stringify() メソッドは、 JavaScript オブジェクトを JSON 文字列に変換します。

+ +
注意:JSON オブジェクトは循環的な構造の変換には対応していません。そのようなオブジェクトを JSON 文字列に変換しようとすると、TypeError 例外が起こります。
+ +

JSON 文字列のパース

+ +

JSON 文字列を JavaScript オブジェクトに変換するには、以下の例のように JSON 文字列を単純に JSON.parse() に渡すだけで済みます。

+ +
var jsObject = JSON.parse(jsonString);
+
+ +

JavaScript 1.8.5 (Firefox 4) 以降では JSON.parse() では末尾のカンマを許可しません。

+ +
// JavaScript 1.8.5 ではいずれも構文エラーとなります
+var jsObject = JSON.parse("[1, 2, 3, 4, ]");
+var jsObject = JSON.parse("{ \"foo\" : 1, }");
+
+ +

オブジェクトを JSON に変換

+ +

JavaScript オブジェクトを JSON 文字列に変換するには、オブジェクトをJSON.stringify() メソッドに渡します:

+ +
var foo = {};
+foo.bar = "new property";
+foo.baz = 3;
+
+var jsonString = JSON.stringify(foo);
+
+ +

jsString'{"bar":"new property","baz":3}' と変換されます。

+ +

Firefox 3.5.4 以降では JSON.stringify() オプションの引数で挙動をカスタマイズ可能になります。構文は次の通りです:

+ +

jsonString = JSON.stringify(value [, replacer [, space]])

+ +
+
value
+
JSON 文字列に変換する JavaScript オブジェクト。
+
replacer
+
文字列化プロセスの振る舞いを変更する関数、または value オブジェクトのプロパティのうち JSON 文字列出力に含めるホワイトリストを指定する String もしくは Number オブジェクトの配列。この値が null もしくは指定されなかった場合、オブジェクトのすべてのプロパティが JSON 文字列の出力に含まれます。
+
space
+
出力される JSON 文字列を読みやすくするために挿入する空白文字を指定する String もしくは Number オブジェクト。Number が指定された場合、ホワイトスペースの空白文字数として扱われます。但し 10 を超える数値を指定しても 10 を指定したものとして扱われます。1 より小さい値を指定するとホワイトスペースは含められません。String が指定された場合、空白文字の代わりにその文字列(または 10 文字を越える場合は最初の 10 文字)が使われます。この値が null もしくは指定されなかった場合、ホワイトスペースは含まれません。
+
+ +

replacer パラメータ

+ +

replacer パラメータには関数または配列を指定できます。

+ +

replacer が関数である場合、文字列化するプロパティのキーと値二つをパラメータとして受け取ります。キーが見つかったオブジェクトは this パラメータとして渡されます。最初空文字列をキー、value パラメータのオブジェクトを値として関数を呼び出します。関数の返り値がオブジェクト(もしくは配列)であれば順次そのプロパティの名前と値を引数として関数を呼び出します。出力される JSON 文字列は関数の返値に応じて次のようになります:

+ + + +
注記: 配列の要素を除外するためには replacer は使えません。オブジェクトのプロパティについては undefined または関数を返すとそのプロパティがスキップされますが、関数の要素の場合は null が出力されます。
+ +

+ +
function replacer(key, value) {
+  if (typeof value === "string") {
+    return undefined;
+  }
+  return value;
+}
+
+var foo = {foundation: "Mozilla", model: "box", week: 45, transport: "car", month: 7};
+var jsonString = JSON.stringify(foo, replacer);
+
+ +

結果として得られる JSON 文字列は {"week":45,"month":7} となります。

+ +

replacer が配列である場合、オブジェクトのプロパティのうち JSON 文字列出力に含まれるべきプロパティ名のリストとして扱われます。

+ +

参考文献

+ + diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/string/lastindexof/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/string/lastindexof/index.html new file mode 100644 index 0000000000..1dc9e038db --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/string/lastindexof/index.html @@ -0,0 +1,18 @@ +--- +title: lastIndexOf +slug: lastIndexOf +tags: + - Disambiguation +translation_of: Web/JavaScript/Reference/Global_Objects/String/lastIndexOf +translation_of_original: lastIndexOf +--- +

lastIndexOf は、いくつかの JavaScript オブジェクトが持つメソッドです。

+ +

JavaScript

+ + + +

これはあいまい性除去のページです — 同じ題名を共有している可能性のあるページをリストして案内を補助します。 記事のリンクからここに来たのであれば、戻って意図するページに直接行くように修正することもできます。

diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/unescape/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/unescape/index.html new file mode 100644 index 0000000000..07564a02ee --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/unescape/index.html @@ -0,0 +1,34 @@ +--- +title: window.unescape +slug: Web/API/Window/unescape +tags: + - DOM + - DOM_0 + - Gecko + - Gecko DOM Reference + - Window +translation_of: Web/JavaScript/Reference/Global_Objects/unescape +translation_of_original: Web/API/Window.unescape +--- +
+ {{ApiRef}}
+

概要

+

16 進でエンコードされた値(例えば、クッキー)をデコードします。

+

構文

+
regular = window.unescape(escaped)
+ +

+
alert( unescape("%5C") );  // 表示結果: "\"
+
+alert( unescape("https%3A//developer.mozilla.org") );  // 表示結果: "https://developer.mozilla.org"
+
+

仕様

+

{{DOM0}} 但し、ECMA-262 の非標準化セクションで言及されています。

+

関連情報

+ diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/instance/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/instance/index.html new file mode 100644 index 0000000000..fedccef945 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/instance/index.html @@ -0,0 +1,64 @@ +--- +title: WebAssembly.Instance.prototype +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/prototype +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance +translation_of_original: Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/prototype +--- +
{{JSRef}} {{SeeCompatTable}}
+ +

WebAssembly.Instance.prototype プロパティは {{jsxref("WebAssembly.Instance()")}} コンストラクタのプロトタイプを表します。

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

説明

+ +

全ての {{jsxref("WebAssembly.Instance")}} インスタンスは Instance.prototype を継承します。{{jsxref("WebAssembly.Instance()")}} コンストラクタのプロトタイプオブジェクトは全ての {{jsxref( "WebAssembly.Instance")}} インスタンスに影響するように変更可能です。 

+ +

プロパティ

+ +
+
Instance.prototype.constructor
+
このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは  {{jsxref("WebAssembly.Instance()")}} コンストラクタです。
+
Instance.prototype.exports {{readonlyinline}}
+
WebAssembly モジュールインスタンスからエクスポートされた全ての関数をメンバとして持つオブジェクトを返します。これらは、JavaScriptからアクセスして使用することができます。
+
+ +

メソッド

+ +

なし。

+ +

仕様

+ + + + + + + + + + + + + + + + +
仕様策定状況コメント
{{SpecName('WebAssembly JS', '#webassemblymodule-objects', 'WebAssembly.Module()')}}{{Spec2('WebAssembly JS')}}初回ドラフト定義
+ +

ブラウザ実装状況

+ +
+ + +

{{Compat("javascript.builtins.WebAssembly.Instance.prototype")}}

+
+ +

関連情報

+ + diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/memory/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/memory/index.html new file mode 100644 index 0000000000..6d837f2f73 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/memory/index.html @@ -0,0 +1,71 @@ +--- +title: WebAssembly.Memory.prototype +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/prototype +tags: + - JavaScript + - Property + - Prototype + - WebAssembly + - memory +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory +translation_of_original: Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/prototype +--- +
{{JSRef}} {{SeeCompatTable}}
+ +

WebAssembly.Memory.prototype プロパティは {{jsxref("WebAssembly.Memory()")}} コンストラクタのプロトタイプを表します。

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

説明

+ +

全ての {{jsxref("WebAssembly.Memory")}} インスタンスは Memory.prototype を継承します。 {{jsxref("WebAssembly.Memory()")}} コンストラクタのプロトタイプオブジェクトは全ての {{jsxref( "WebAssembly.Memory")}} インスタンスに影響するように変更可能です。

+ +

プロパティ

+ +
+
Memory.prototype.constructor
+
このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは {{jsxref("WebAssembly.Memory()")}} コンストラクタです。
+
{{jsxref("WebAssembly/Memory/buffer","Memory.prototype.buffer")}}
+
メモリーに格納されているバッファを返すアクセサプロパティ。
+
+

メソッド

+
+
{{jsxref("WebAssembly/Memory/grow","Memory.prototype.grow()")}}
+
指定した WebAssembly ページの数 (64KBを1単位とする) で Memory インスタンスのサイズを増やします。
+
+ +

仕様

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

ブラウザ実装状況

+ +
+ + +

{{Compat("javascript.builtins.WebAssembly.Memory.prototype")}}

+
+ +

関連情報

+ + diff --git a/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/table/index.html b/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/table/index.html new file mode 100644 index 0000000000..84709eb736 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/global_objects/webassembly/table/index.html @@ -0,0 +1,75 @@ +--- +title: WebAssembly.Table.prototype +slug: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/prototype +tags: + - JavaScript + - Property + - Prototype + - WebAssembly + - table +translation_of: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table +translation_of_original: Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/prototype +--- +
{{JSRef}} {{SeeCompatTable}}
+ +

WebAssembly.Table.prototype プロパティは {{jsxref("WebAssembly.Table()")}} コンストラクタのプロトタイプを表します。

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

説明

+ +

全ての {{jsxref("WebAssembly.Table")}} インスタンスは Table.prototype を継承します。{{jsxref("WebAssembly.Table()")}} コンストラクタのプロトタイプオブジェクトは全ての {{jsxref( "WebAssembly.Table")}} インスタンスに影響するように変更可能です。

+ +

プロパティ

+ +
+
Table.prototype.constructor
+
このオブジェクトのインスタンスを生成した関数を返します。デフォルトでは  {{jsxref("WebAssembly.Table()")}} コンストラクタです。
+
{{jsxref("WebAssembly/Table/length","Table.prototype.length")}}
+
テーブルの長さを返します。すなわち、要素数です。
+
+

メソッド

+
+
{{jsxref("WebAssembly/Table/get","Table.prototype.get()")}}
+
アクセサ関数。インデックスから格納された要素を取得します。
+
{{jsxref("WebAssembly/Table/grow","Table.prototype.grow()")}}
+
指定した要素数で Table インスタンスを拡張します。
+
{{jsxref("WebAssembly/Table/set","Table.prototype.set()")}}
+
指定したインデックスに要素を格納します。
+
+ +

仕様

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

ブラウザ実装状況

+ +
+ + +

{{Compat("javascript.builtins.WebAssembly.Table.prototype")}}

+
+ +

関連情報

+ + diff --git a/files/ja/conflicting/web/javascript/reference/lexical_grammar/index.html b/files/ja/conflicting/web/javascript/reference/lexical_grammar/index.html new file mode 100644 index 0000000000..fabc275890 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/lexical_grammar/index.html @@ -0,0 +1,89 @@ +--- +title: 予約語 +slug: Web/JavaScript/Reference/Reserved_Words +tags: + - JavaScript +translation_of: Web/JavaScript/Reference/Lexical_grammar#Keywords +translation_of_original: Web/JavaScript/Reference/Reserved_Words +--- +

以下は予約語であり、変数、関数、メソッド、あるいはオブジェクトの識別子として用いることはできません。以下は ECMAScript の仕様で既存のキーワードとして予約されているものです。

+ +
+ +
+ +

将来の使用を見越した予約語

+ +

以下は ECMAScript の仕様で将来のキーワードとして予約されているものです。現在は特別な機能を持っていませんが、将来機能を持つときのために、識別子として使用できません。このキーワードは、厳格モード、非厳格モードの両方で使用できません。

+ +
注記: Firefox 5 (JavaScript 1.8.6) より以前では、これらのキーワードは厳格モードでないときには使用できました。この ECMAScript 違反は Firefox 5 で修正されました。
+ +
+ +
+ +

以下は 厳格モードのコード として実行されたときに 、ECMAScript の仕様で将来のキーワードとして 予約されているものです。ただし、JavaScript 1.7 以上では letyield は伝統的な Mozilla 特有の機能を持っています。

+ +
+ +
+ +

const は ECMAScript の仕様によって将来のキーワードとして予約されていますが、Mozilla やほとんどの他のブラウザが非標準の拡張として実装していることに注意してください。さらに、 exportimport はかつて Mozilla で実装されていましたが、現在では予約語となっています。

+ +

加えて、 nulltruefalse リテラルは ECMAScript の仕様で予約されています。

+ +

予約語の利用

+ +

実際に、予約語は識別子のみに適用されます。es5.github.com/#A.1 の記述にあるように、これらは全て予約語を排除しない識別名です。

+ +

a.import
+ a["import"]
+ a = { import: "test" }.

+ +

反対に、以下は識別子であるので違反です。識別子は関数宣言や関数式に使用されます。

+ +

function import() {}

diff --git a/files/ja/conflicting/web/javascript/reference/operators/index.html b/files/ja/conflicting/web/javascript/reference/operators/index.html new file mode 100644 index 0000000000..5010c8eb89 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/operators/index.html @@ -0,0 +1,232 @@ +--- +title: 比較演算子 +slug: Web/JavaScript/Reference/Operators/Comparison_Operators +tags: + - JavaScript + - Operator + - Reference + - 演算子 +translation_of: Web/JavaScript/Reference/Operators +translation_of_original: Web/JavaScript/Reference/Operators/Comparison_Operators +--- +
{{jsSidebar("Operators")}}
+ +

JavaScript には、厳密な比較と型変換の比較の両方があります。厳密な比較 (例: ===) は、オペランドが同じ型で、内容も一致している場合にのみ真になります。もっとよく使用される抽象的な比較 (例: ==) は、比較する前にオペランドを同じ型に変換します。抽象的な関係比較 (例: <=) では、比較前にまずオペランドがプリミティブ型に変換され、それから同じ型に変換されます。

+ +

文字列は Unicode 値を使用した標準的な辞書順に基づいて比較されます。

+ +
{{EmbedInteractiveExample("pages/js/expressions-equality.html")}}
+ +
+
{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}
+
+ +
+ + + +

比較の機能は以下のとおりです。

+ + + +

等価演算子

+ +

等価 (==)

+ +

等価演算子は、2 つのオペランドが同じ型でないならばオペランドを変換して、それから厳密な比較を行います。両方のオペランドがオブジェクトならば、 JavaScript は内部参照を比較するので、オペランドがメモリ内の同じオブジェクトを参照するときに等しくなります。

+ +

構文

+ +
x == y
+
+ +

+ +
1    ==  1         // true
+'1'  ==  1         // true
+1    == '1'        // true
+0    == false      // true
+0    == null       // false
+var object1 = {'key': 'value'}, object2 = {'key': 'value'};
+object1 == object2 // false
+0    == undefined  // false
+null == undefined  // true
+
+ +

不等価 (!=)

+ +

不等価演算子は、オペランド同士が等しくないならば真を返します。2 つのオペランドが同じ型でないならば、JavaScript は適切な型にオペランドを変換して比較しようとします。両方のオペランドがオブジェクトならば、JavaScript は内部参照を比較するので、オペランドがメモリ内の異なるオブジェクトを参照するときには等しくなりません。

+ +

構文

+ +
x != y
+ +

+ +
1 !=   2     // true
+1 !=  '1'    // false
+1 !=  "1"    // false
+1 !=  true   // false
+0 !=  false  // false
+
+ +

一致 / 厳密等価 (===)

+ +

厳密等価演算子は、型変換なしでオペランド同士が (上に示した通り) 厳密に等しければ真を返します。

+ +

構文

+ +
x === y
+ +

+ +
3 === 3   // true
+3 === '3' // false
+var object1 = {'key': 'value'}, object2 = {'key': 'value'};
+object1 === object2 //false
+ +

不一致 / 厳密不等価 (!==)

+ +

厳密不等価演算子は、オペランド同士が等しくないか、型が等しくない、あるいはその両方ならば真を返します。

+ +

構文

+ +
x !== y
+ +

+ +
3 !== '3' // true
+4 !== 3   // true
+
+ +

関係演算子

+ +

これらの演算子のそれぞれは、比較が行われる前に、そのオペランドをプリミティブに{{Glossary("Type_coercion", "型強制")}}します。両方とも文字列として終わる場合は、辞書順で比較され、そうでない場合は数値に変換されて比較されます。 NaN との比較は常に false を生み出します。

+ +

大なり演算子 (>)

+ +

大なり演算子は、左オペランドが右オペランドより大きければ、真を返します。

+ +

構文

+ +
x > y
+ +

+ +
4 > 3 // true
+
+ +

大なりイコール演算子 (>=)

+ +

大なりイコール演算子は、左オペランドが右オペランド以上ならば、真を返します。

+ +

構文

+ +
 x >= y
+ +

+ +
4 >= 3 // true
+3 >= 3 // true
+
+ +

小なり演算子 (<)

+ +

小なり演算子は、左オペランドが右オペランドより小さければ、真を返します。

+ +

構文

+ +
 x < y
+ +

+ +
3 < 4 // true
+
+ +

小なりイコール演算子 (<=)

+ +

小なりイコール演算子は、左オペランドが右オペランド以下ならば、真を返します。

+ +

構文

+ +
 x <= y
+ +

+ +
3 <= 4 // true
+3 <= 3 // true
+
+ +

等価演算子の使用

+ +

標準等価演算子 (==!=) は 2 つのオペランドの比較に抽象的等価比較アルゴリズムを使用します。オペランドの型が異なる場合は、比較を行う前にそれらを同じ型に変換しようとします。例えば 5 == '5' という式では、比較を行う前に右オペランドの文字列を数値に変換します。

+ +

厳密等価演算子 (===!==) は厳密等価比較アルゴリズムを使用して、オペランドの型が同一かどうかに関する比較も行います。オペランドの型が異なれば、例えば 5'5' の比較では、同一性比較 5 !== '5'true と評価され、 5 === '5' のチェックは false 評価されます。

+ +

厳密等価演算子を使うのは、オペランドが特定の型の特定の値でなければならない場合、言い換えればオペランドの正確な型が重要な場合です。それ以外では、2 つのオペランドが同じ型でなくても比較が可能になる、標準的な等価演算子を使えます。

+ +

比較に型の変換が関わるとき (つまり厳密でない比較のとき)、 JavaScript は以下のように {{jsxref("String")}}, {{jsxref("Number")}}, {{jsxref("Boolean")}}, {{jsxref("Object")}} 型のオペランドを変換します。

+ + + +
メモ: String オブジェクトはオブジェクト型であり、文字列型ではありません! String オブジェクトはほとんど使わないので、次の結果に驚くかもしれません。
+ +
// 両方のオペランドが文字列型 (すなわちプリミティブな文字列) なので、true
+'foo' === 'foo'
+
+var a = new String('foo');
+var b = new String('foo');
+
+// a と b はオブジェクト型で、異なるオブジェクトを参照しているので、false
+a == b
+
+// a と b はオブジェクト型で、異なるオブジェクトを参照しているので、false
+a === b
+
+// a と 'foo' は異なる型で、比較前にオブジェクト (a) は
+// 文字列 'foo' に変換されるので、真
+a == 'foo'
+ +

仕様書

+ + + + + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-equality-operators', 'Equality Operators')}}
{{SpecName('ESDraft', '#sec-relational-operators', 'Relational Operators')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.operators.comparison")}}

+ +

関連情報

+ + diff --git a/files/ja/conflicting/web/javascript/reference/operators/yield/index.html b/files/ja/conflicting/web/javascript/reference/operators/yield/index.html new file mode 100644 index 0000000000..69be44e8d9 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/operators/yield/index.html @@ -0,0 +1,7 @@ +--- +title: yield +slug: Web/JavaScript/Reference/Statements/yield +translation_of: Web/JavaScript/Reference/Operators/yield +translation_of_original: Web/JavaScript/Reference/Statements/yield +--- +

JavaScript 1.7 の新機能』、『イテレータとジェネレータ』 を参照して下さい。

diff --git a/files/ja/conflicting/web/javascript/reference/operators_f71733c8e7001a29c3ec40d8522a4aca/index.html b/files/ja/conflicting/web/javascript/reference/operators_f71733c8e7001a29c3ec40d8522a4aca/index.html new file mode 100644 index 0000000000..8b43c3de26 --- /dev/null +++ b/files/ja/conflicting/web/javascript/reference/operators_f71733c8e7001a29c3ec40d8522a4aca/index.html @@ -0,0 +1,295 @@ +--- +title: 論理演算子 +slug: Web/JavaScript/Reference/Operators/Logical_Operators +tags: + - JavaScript + - Operator +translation_of: Web/JavaScript/Reference/Operators +translation_of_original: Web/JavaScript/Reference/Operators/Logical_Operators +--- +
{{jsSidebar("Operators")}}
+ +

概要

+ +

{{ 原語併記("論理演算子", "Logical operators") }} は、基本的に真偽(論理)値とともに用いられ真偽値を返します。しかし、&& および || 演算子は真偽値ではない値も使うことができるため、その場合は、真偽値ではない値を返すことがあります。その場合の考え方は以下の「説明」の欄の記載の通りとなります。

+ +

説明

+ +

論理演算子を以下の表で説明します。:

+ + + + + + + + + + + + + + + + + + + + + + + + +
演算子使用法説明
論理 AND(&&)expr1 && expr2expr1 を false と見ることができる場合は、expr1 を返します。そうでない場合は、expr2 を返します。したがって、真偽値と共に使われた場合、 演算対象の両方が true ならば、&& は、true を返し、そうでなければ、false を返します。
論理 OR (||)expr1 || expr2expr1 を true と見ることができる場合は、expr1 を返します。そうでない場合は、expr2 を返します。したがって、真偽値と共に使われた場合、 演算対象のどちらかが true ならば、|| は、true を返し、両方とも false の場合は、false を返します。
論理 NOT (!)!expr単一の演算対象が true と見ることができる場合は、false を返します。そうでない場合は、true を返します。
+ +

true に変換できる値は、いわゆる {{Glossary("truthy")}} です。false に変換できる値は、いわゆる {{Glossary("falsy")}} です。

+ +

false と見ることができる式の例は、null、0、空文字列 ("")、あるいは、undefined と評価されるものです。

+ +

&&|| 演算子が真偽値ではない値である演算対象とともに用いることができても、それらは、真偽演算子と考えることができます。なぜなら、それらの戻り値は、常に、真偽値と見ることができるからです。

+ +

ショートサーキット評価

+ +

論理演算子は左から右へ評価されるため、論理演算子で左辺を評価した時点で論理式の結果が確定した場合には右辺の評価を行わないことを、ショートサーキット評価といいます。例えば、A && Bという論理式があった場合、Aがfalseなら、その時点で式全体の結果はfalseで確定するため、Bがどうであるかについてはチェックしません。:

+ + + +

 上記の式の anything の部分は評価されません。また、上記の式の anything の部分は (括弧で示しているとおり) ひとつの論理式ですので注意してください。

+ +

例えば、以下の 2 つの関数は等価です。

+ +
function shortCircuitEvaluation() {
+  doSomething() || doSomethingElse()
+}
+
+function equivalentEvaluation() {
+  var flag = doSomething();
+  if (!flag) {
+    doSomethingElse();
+  }
+}
+
+ +

しかし、以下の式は等価ではありません。これは演算子の優先順位のためであり、右側の演算子をひとつの式にする (必要に応じて括弧でグループ化する) 必要性の重要度を高めています。

+ +
false && true  || true      // true を返す
+false && (true || true)     // false を返す
+ +

論理 AND (&&)

+ +

以下のコードは、&& (論理 AND) 演算子の例を示しています。

+ +
a1 = true  && true      // t && t true を返します。
+a2 = true  && false     // t && f false を返します。
+a3 = false && true      // f && t false を返します。
+a4 = false && (3 == 4)  // f && f false を返します。
+a5 = "Cat" && "Dog"     // t && t "Dog" を返します。
+a6 = false && "Cat"     // f && t false を返します。
+a7 = "Cat" && false     // t && f false を返します。
+
+ +

論理 OR (||)

+ +

以下のコードは、|| (論理 OR) 演算子の例を示しています。

+ +
o1 = true  || true       // t || t true を返します。
+o2 = false || true       // f || t true を返します。
+o3 = true  || false      // t || f true を返します。
+o4 = false || (3 == 4)   // f || f false を返します。
+o5 = "Cat" || "Dog"      // t || t "Cat" を返します。
+o6 = false || "Cat"      // f || t "Cat" を返します。
+o7 = "Cat" || false      // t || f "Cat" を返します。
+
+ +

論理 NOT (!)

+ +

以下のコードは、! (論理 NOT) 演算子の例を示しています。

+ +
n1 = !true              // !t false を返します。
+n2 = !false             // !f true を返します。
+n3 = !"Cat"             // !t false を返します。
+
+ +

変換規則

+ +

AND から OR への変換

+ +

Boolean について以下の演算を行います:

+ +
bCondition1 && bCondition2
+ +

これは以下の演算と等価です:

+ +
!(!bCondition1 || !bCondition2)
+ +

OR から AND への変換

+ +

Boolean について以下の演算を行います:

+ +
bCondition1 || bCondition2
+ +

これは以下の演算と等価です:

+ +
!(!bCondition1 && !bCondition2)
+ +

NOT 間の変換

+ +

Boolean について以下の演算を行います:

+ +
!!bCondition
+ +

これは以下の演算と等価です:

+ +
bCondition
+ +

入れ子の括弧を削除する

+ +

論理演算子は左から右へ評価されるため、複雑な式の中にある括弧をいくつかの規則に従って削除することができます。

+ +

入れ子の AND を削除する

+ +

Boolean について以下の複雑な演算を行います:

+ +
bCondition1 || (bCondition2 && bCondition3)
+ +

これは以下の演算と等価です:

+ +
bCondition1 || bCondition2 && bCondition3
+ +

入れ子の OR を削除する

+ +

Boolean について以下の複雑な演算を行います:

+ +
bCondition1 && (bCondition2 || bCondition3)
+ +

これは以下の演算と等価です:

+ +
!(!bCondition1 || !bCondition2 && !bCondition3)
+ +

仕様

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
仕様書策定状況コメント
{{SpecName('ES1')}}{{Spec2('ES1')}}最初期の定義
{{SpecName('ES5.1', '#sec-11.11')}}{{Spec2('ES5.1')}}仕様書内のいくつかのセクションで定義: Logical NOT Operator, Binary Logical Operators
{{SpecName('ES6', '#sec-binary-logical-operators')}}{{Spec2('ES6')}}仕様書内のいくつかのセクションで定義: Logical NOT Operator, Binary Logical Operators
{{SpecName('ESDraft', '#sec-binary-logical-operators')}}{{Spec2('ESDraft')}}仕様書内のいくつかのセクションで定義: Logical NOT Operator, Binary Logical Operators
+ +

ブラウザ実装状況

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
機能ChromeFirefox (Gecko)Internet ExplorerOperaSafari
論理 AND (&&){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
論理 OR (||){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
論理 NOT (!){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
機能AndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
論理 AND (&&){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
論理 OR (||){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
論理 NOT (!){{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf