From e968c7e8d8c55cbcfed3a561a74162d6cee5e5c7 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Wed, 9 Jun 2021 01:48:21 +0900 Subject: Web/JavaScript/Reference/Errors/C* を更新 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2021/03/29 時点の英語版に同期 --- .../errors/called_on_incompatible_type/index.html | 36 ++++++++++---------- .../errors/cant_access_property/index.html | 35 ++++++++++--------- .../errors/cant_assign_to_property/index.html | 34 ++++++++++--------- .../index.html | 36 +++++++++++--------- .../reference/errors/cant_delete/index.html | 39 +++++++++++++--------- 5 files changed, 99 insertions(+), 81 deletions(-) diff --git a/files/ja/web/javascript/reference/errors/called_on_incompatible_type/index.html b/files/ja/web/javascript/reference/errors/called_on_incompatible_type/index.html index aaf0d62155..f1f15add68 100644 --- a/files/ja/web/javascript/reference/errors/called_on_incompatible_type/index.html +++ b/files/ja/web/javascript/reference/errors/called_on_incompatible_type/index.html @@ -2,42 +2,42 @@ title: 'TypeError: X.prototype.y called on incompatible type' slug: Web/JavaScript/Reference/Errors/Called_on_incompatible_type tags: - - Error - - Errors - - JavaScript - - TypeError +- Error +- Errors +- JavaScript +- TypeError translation_of: Web/JavaScript/Reference/Errors/Called_on_incompatible_type ---
{{jsSidebar("Errors")}}

JavaScript の例外 "called on incompatible target (or object)" は、関数が (与えられたオブジェクト上で) 呼び出されたときに、関数が期待する型に対応していない this を使用して呼び出された場合に発生します。

-

メッセージ

+

エラーメッセージ

-
TypeError: 'this' is not a Set object (EdgE)
+
TypeError: 'this' is not a Set object (Edge)
 TypeError: Function.prototype.toString called on incompatible object (Firefox)
 TypeError: Function.prototype.bind called on incompatible target (Firefox)
 TypeError: Method Set.prototype.add called on incompatible receiver undefined (Chrome)
 TypeError: Bind must be called on a function (Chrome)
 
-

エラー種別

+

エラーの種類

{{jsxref("TypeError")}}

-

原因

+

エラーの原因

-

このエラーがスローされる場合、(指定されたオブジェクト上の) 関数が、関数が予期する型に対応していない this と共に呼び出されています。

+

このエラーが発生する場合、(指定されたオブジェクト上の) 関数が、関数が予期する型に対応していない this と共に呼び出されています。

この問題は {{jsxref("Function.prototype.call()")}} メソッドか {{jsxref("Function.prototype.apply()")}} メソッドを使用して、予期していない型の this 引数を渡した場合に発生します。

この問題は、オブジェクトのプロパティとして格納されている関数を他の関数の引数として提供する場合にも発生します。この場合、関数を格納しているオブジェクトは、他の関数から呼び出されたときに、その関数の this のターゲットにはなりません。この問題を回避するには、呼び出しを行っているラムダを提供するか、 {{jsxref("Function.prototype.bind()")}} 関数を使用して this 引数を期待されるオブジェクトに強制的に渡す必要があります。

-

+

-

無効な場合

+

無効な場合

-
var mySet = new Set;
+
var mySet = new Set;
 ['bar', 'baz'].forEach(mySet.add);
 // mySet.add is a function, but "mySet" is not captured as this.
 
@@ -49,9 +49,9 @@ var myFun = function () {
 
 
-

妥当な場合

+

妥当な場合

-
var mySet = new Set;
+
var mySet = new Set;
 ['bar', 'baz'].forEach(mySet.add.bind(mySet));
 // This works due to binding "mySet" as this.
 
@@ -63,10 +63,10 @@ var myFun = function () {
 
 
-

関連情報

+

関連情報

    -
  • {{jsxref("Function.prototype.call()")}}
  • -
  • {{jsxref("Function.prototype.apply()")}}
  • -
  • {{jsxref("Function.prototype.bind()")}}
  • +
  • {{jsxref("Function.prototype.call()")}}
  • +
  • {{jsxref("Function.prototype.apply()")}}
  • +
  • {{jsxref("Function.prototype.bind()")}}
diff --git a/files/ja/web/javascript/reference/errors/cant_access_property/index.html b/files/ja/web/javascript/reference/errors/cant_access_property/index.html index b9bd300b79..a2fc8a56b4 100644 --- a/files/ja/web/javascript/reference/errors/cant_access_property/index.html +++ b/files/ja/web/javascript/reference/errors/cant_access_property/index.html @@ -2,38 +2,41 @@ title: 'TypeError: can''t access property "x" of "y"' slug: Web/JavaScript/Reference/Errors/Cant_access_property tags: - - Error - - JavaScript - - TypeError +- Error +- Errors +- JavaScript +- TypeError translation_of: Web/JavaScript/Reference/Errors/Cant_access_property ---
{{jsSidebar("Errors")}}
-

メッセージ

+

JavaScript の例外 "can't access property" は、 {{jsxref("undefined")}} または {{jsxref("null")}} の値に対してプロパティのアクセスが行われた場合に発生します。

-
TypeError: Unable to get property {x} of undefined or null reference (Edge)
+

エラーメッセージ

+ +
TypeError: Unable to get property {x} of undefined or null reference (Edge)
 TypeError: can't access property {x} of {y} (Firefox)
 TypeError: {y} is undefined, can't access property {x} of it (Firefox)
 TypeError: {y} is null, can't access property {x} of it (Firefox)
 
-Examples:
+例:
 TypeError: x is undefined, can't access property "prop" of it
 TypeError: x is null, can't access property "prop" of it
 TypeError: can't access property "prop" of undefined
 TypeError: can't access property "prop" of null
 
-

エラータイプ

+

エラーの種類

-

{{jsxref("TypeError")}}。

+

{{jsxref("TypeError")}}

-

何がうまくいかなかったのか?

+

エラーの原因

{{jsxref("undefined")}} か {{jsxref("null")}} に対してプロパティアクセスを行いました。

-

+

-

無効なケース

+

無効な場合

// undefined and null cases on which the substring method won't work
 var foo = undefined;
@@ -43,17 +46,17 @@ var foo = null;
 foo.substring(1); // TypeError: x is null, can't access property "substring" of it
 
-

問題解決

+

問題の修正

-

undefinednull の null pointer アクセスを修正するには、たとえば typeof 演算子を使用できます。

+

undefinednull のヌルポインターアクセスを修正するには、たとえば typeof 演算子を使用することができます。

if (typeof foo !== 'undefined') {
   // Now we know that foo is defined, we are good to go.
 }
-

関連項目

+

関連情報

    -
  • {{jsxref("undefined")}}
  • -
  • {{jsxref("null")}}
  • +
  • {{jsxref("undefined")}}
  • +
  • {{jsxref("null")}}
diff --git a/files/ja/web/javascript/reference/errors/cant_assign_to_property/index.html b/files/ja/web/javascript/reference/errors/cant_assign_to_property/index.html index 8a9564ddc4..97f63535f9 100644 --- a/files/ja/web/javascript/reference/errors/cant_assign_to_property/index.html +++ b/files/ja/web/javascript/reference/errors/cant_assign_to_property/index.html @@ -10,36 +10,38 @@ translation_of: Web/JavaScript/Reference/Errors/Cant_assign_to_property ---
{{jsSidebar("Errors")}}
-

メッセージ

+

JavaScript の strict モードの例外 "can't assign to property" は、プリミティブ値、例えばシンボル文字列数値論理値などにプロパティを作成しようとしたときに発生します。プリミティブ値はいかなるプロパティを持つこともできません。

-
TypeError: can't assign to property "x" on {y}: not an object (Firefox)
+

エラーメッセージ

+ +
TypeError: can't assign to property "x" on {y}: not an object (Firefox)
 TypeError: Cannot create property 'x' on {y} (Chrome)
 
-

エラータイプ

+

エラーの種類

-

{{jsxref("TypeError")}}.

+

{{jsxref("TypeError")}}

-

何がうまくいかなかったのか?

+

エラーの原因

-

In {{jsxref("Strict_mode")}}, a {{jsxref("TypeError")}} is raised when attempting to create a property on {{Glossary("primitive")}} value such as a {{Glossary("symbol")}}, a {{Glossary("string")}}, a {{Glossary("number")}} or a {{Glossary("boolean")}}. {{Glossary("Primitive")}} values cannot hold any {{Glossary("property/JavaScript", "property")}}.

+

{{jsxref("Strict_mode", "Strict モード", "", 1)}}では、 {{jsxref("TypeError")}} はプリミティブ値、例えばシンボル文字列数値論理値などにプロパティを作成しようとしたときに発生します。プリミティブ値はいかなるプロパティを持つこともできません。

-

The problem might be that an unexpected value is flowing at an unexpected place, or that an object variant of a {{jsxref("String")}} or a {{jsxref("Number")}} is expected.

+

想定外の場所に想定外の値が流れてきたり、 {{jsxref("String")}} や {{jsxref("Number")}} のオブジェクトバリアントが想定されていたりすることが問題となることがあります。

-

+

-

無効なケース

+

無効な場合

'use strict';
 
 var foo = "my string";
-// The following line does nothing if not in strict mode.
-foo.bar = {}; // TypeError: can't assign to property "bar" on "my string": not an object
+// 次の行は strict モードでない場合は何もしません。
+foo.bar = {}; // TypeError: can't assign to property "bar" on "my string": not an object
 
-

問題を修正する

+

問題の修正

-

Either fix the code to prevent the {{Glossary("primitive")}} from being used in such places, or fix the issue is to create the object equivalent {{jsxref("Object")}}.

+

このような場所でプリミティブ値を使用しないようにコードを修正するか、 {{jsxref("Object")}} と同等のオブジェクトを生成して問題を修正するかします。

'use strict';
 
@@ -47,9 +49,9 @@ var foo = new String("my string");
 foo.bar = {};
 
-

あわせて参照

+

関連情報

    -
  • {{jsxref("Strict_mode")}}
  • -
  • {{Glossary("primitive")}}
  • +
  • {{jsxref("Strict_mode", "Strict モード", "", 1)}}
  • +
  • プリミティブ
diff --git a/files/ja/web/javascript/reference/errors/cant_define_property_object_not_extensible/index.html b/files/ja/web/javascript/reference/errors/cant_define_property_object_not_extensible/index.html index cc0eeecd06..fd01cab4ec 100644 --- a/files/ja/web/javascript/reference/errors/cant_define_property_object_not_extensible/index.html +++ b/files/ja/web/javascript/reference/errors/cant_define_property_object_not_extensible/index.html @@ -2,31 +2,37 @@ title: 'TypeError: can''t define property "x": "obj" is not extensible' slug: Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible tags: - - Error - - Errors - - JavaScript - - TypeError +- Error +- Errors +- JavaScript +- TypeError translation_of: Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible ---
{{jsSidebar("Errors")}}
-

メッセージ

+

JavaScript の例外 "can't define property "x": "obj" is not extensible" は {{jsxref("Object.preventExtensions()")}} でオブジェクトが拡張可能ではなくなったため、その時点で存在していたプロパティを設定できなかった際に発生します。

-
TypeError: can't define property "x": "obj" is not extensible (Firefox)
+

エラーメッセージ

+ +
TypeError: Cannot create property for a non-extensible object (Edge)
+TypeError: can't define property "x": "obj" is not extensible (Firefox)
 TypeError: Cannot define property: "x", object is not extensible. (Chrome)
 
-

エラータイプ

+

エラーの種類

{{jsxref("TypeError")}}

-

何がうまくいかなかったのか?

+

エラーの原因

通常、オブジェクトは拡張可能で、新しいプロパティを追加できます。しかしこの場合は、{{jsxref("Object.preventExtensions()")}} がオブジェクトをもはや拡張できないものに設定しているため、拡張不可のマークが付けられたときにあったプロパティ以上のプロパティを追加できません。

-

+

+ +

Adding new properties to a + non-extensible objects

-

strict モードでは、拡張不可のオブジェクトに新しいプロパティを追加しようとすると TypeError をスローします。非 strict モードでは、"x" プロパティの追加は暗黙的に無視されます。

+

strict モードでは、拡張不可のオブジェクトに新しいプロパティを追加しようとすると TypeError が発生します。非 strict モードでは、"x" プロパティの追加は暗黙的に無視されます。

'use strict';
 
@@ -37,7 +43,7 @@ obj.x = 'foo';
 // TypeError: can't define property "x": "obj" is not extensible
 
-

strict モードと非 strict モード共に、拡張不可のオブジェクトに新しいプロパティを追加しようとして {{jsxref("Object.defineProperty()")}} を呼び出すと、例外をスローします。

+

strict モードと非 strict モード共に、拡張不可のオブジェクトに新しいプロパティを追加しようとして {{jsxref("Object.defineProperty()")}} を呼び出すと、例外が発生します。

var obj = { };
 Object.preventExtensions(obj);
@@ -48,17 +54,17 @@ Object.defineProperty(obj,
 // TypeError: can't define property "x": "obj" is not extensible
 
-

このエラーを修正するには、{{jsxref("Object.preventExtensions()")}} の呼び出しを削除するか、オブジェクトが拡張不可とマークされる前にプロパティを追加するように移動する必要があります。もちろん、必要がないのであれば、追加しようとしているプロパティを削除しても良いです。

+

このエラーを修正するには、{{jsxref("Object.preventExtensions()")}} の呼び出しを削除するか、オブジェクトが拡張不可とマークされる前にプロパティを追加するように移動する必要があります。もちろん、必要がないのであれば、追加しようとしているプロパティを削除しても構いません。

'use strict';
 
 var obj = {};
-obj.x = 'foo'; // add property first and only then prevent extensions
+obj.x = 'foo'; // プロパティを追加してから拡張不可にする
 
 Object.preventExtensions(obj);
-

関連項目

+

関連情報

    -
  • {{jsxref("Object.preventExtensions()")}}
  • +
  • {{jsxref("Object.preventExtensions()")}}
diff --git a/files/ja/web/javascript/reference/errors/cant_delete/index.html b/files/ja/web/javascript/reference/errors/cant_delete/index.html index 2e2a44b27d..ca431a4ab7 100644 --- a/files/ja/web/javascript/reference/errors/cant_delete/index.html +++ b/files/ja/web/javascript/reference/errors/cant_delete/index.html @@ -2,6 +2,7 @@ title: 'TypeError: property "x" is non-configurable and can''t be deleted' slug: Web/JavaScript/Reference/Errors/Cant_delete tags: + - Error - Errors - JavaScript - Strict Mode @@ -10,46 +11,52 @@ translation_of: Web/JavaScript/Reference/Errors/Cant_delete ---
{{jsSidebar("Errors")}}
-

メッセージ

+

JavaScript の例外 "property is non-configurable and can't be deleted" は、プロパティを削除しようとしたが、そのプロパティが構成不可である場合に発生します。

-
TypeError: property "x" is non-configurable and can't be deleted. (Firefox)
+

エラーメッセージ

+ +
TypeError: Calling delete on 'x' is not allowed in strict mode (Edge)
+TypeError: property "x" is non-configurable and can't be deleted. (Firefox)
 TypeError: Cannot delete property 'x' of #<Object> (Chrome)
 
-

エラータイプ

+

エラーの種類

strict モードでのみ、{{jsxref("TypeError")}} の警告が出ます。

-

何がうまくいかなかったのか?

+

エラーの原因

+ +

プロパティを削除しようとしましたが、プロパティが non-configurable でした。configurable 属性は、オブジェクトからプロパティを削除できるかどうか、および (writable を除く) 属性を変更できるかどうかを制御します。

-

プロパティを削除しようとしましたが、プロパティが non-configurable でした。configurable 属性は、オブジェクトからプロパティを削除できるかどうか、および(writable を除く)属性を変更できるかどうかを制御します。

+

このエラーは、strict モードのコード でのみ発生します。非 strict コードでは、この操作は false を返します。

-

このエラーは、strict モードのコード でのみ発生します。非 strict コードでは、この操作は false を返します。

+

-

+

構成不可のプロパティに対する削除の試み

-

non-configurable プロパティは、さほど一般的ではありませんが、{{jsxref("Object.defineProperty()")}} か {{jsxref("Object.freeze()")}} を使用して生成できます。

+

構成不可のプロパティは、さほど一般的ではありませんが、{{jsxref("Object.defineProperty()")}} か {{jsxref("Object.freeze()")}} を使用して生成することができます。

-
"use strict";
-var obj = Object.freeze({name: "Elsa", score: 157});
+
'use strict';
+var obj = Object.freeze({name: 'Elsa', score: 157});
 delete obj.score;  // TypeError
 
-"use strict";
+'use strict';
 var obj = {};
-Object.defineProperty(obj, "foo", {value: 2, configurable: false});
+Object.defineProperty(obj, 'foo', {value: 2, configurable: false});
 delete obj.foo;  // TypeError
 
-"use strict";
+'use strict';
 var frozenArray = Object.freeze([0, 1, 2]);
 frozenArray.pop();  // TypeError
 
-

JavaScript に組み込まれた、少数の non-configurable プロパティもあります。もしかしたら、Math の定数を削除しようとしたのかもしれません。

+

JavaScript に組み込まれた、少数の構成不可プロパティもあります。もしかしたら、Math の定数を削除しようとしたのかもしれません。

-
"use strict";
+
'use strict';
 delete Math.PI;  // TypeError
-

関連項目

+

関連情報

  • delete
  • -- cgit v1.2.3-54-g00ecf