From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../errors/cant_access_property/index.html | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 files/ja/web/javascript/reference/errors/cant_access_property/index.html (limited to 'files/ja/web/javascript/reference/errors/cant_access_property') 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 new file mode 100644 index 0000000000..b9bd300b79 --- /dev/null +++ b/files/ja/web/javascript/reference/errors/cant_access_property/index.html @@ -0,0 +1,59 @@ +--- +title: 'TypeError: can''t access property "x" of "y"' +slug: Web/JavaScript/Reference/Errors/Cant_access_property +tags: + - Error + - JavaScript + - TypeError +translation_of: Web/JavaScript/Reference/Errors/Cant_access_property +--- +
{{jsSidebar("Errors")}}
+ +

メッセージ

+ +
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("undefined")}} か {{jsxref("null")}} に対してプロパティアクセスを行いました。

+ +

+ +

無効なケース

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

問題解決

+ +

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

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

関連項目

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