diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/errors/cant_access_property | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/errors/cant_access_property')
| -rw-r--r-- | files/ja/web/javascript/reference/errors/cant_access_property/index.html | 59 |
1 files changed, 59 insertions, 0 deletions
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 +--- +<div>{{jsSidebar("Errors")}}</div> + +<h2 id="メッセージ">メッセージ</h2> + +<pre class="syntaxbox">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 +</pre> + +<h2 id="エラータイプ">エラータイプ</h2> + +<p>{{jsxref("TypeError")}}。</p> + +<h2 id="何がうまくいかなかったのか?">何がうまくいかなかったのか?</h2> + +<p>{{jsxref("undefined")}} か {{jsxref("null")}} に対してプロパティアクセスを行いました。</p> + +<h2 id="例">例</h2> + +<h3 id="無効なケース">無効なケース</h3> + +<pre class="brush: js example-bad">// 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 +</pre> + +<h3 id="問題解決">問題解決</h3> + +<p><code>undefined</code> か <code>null</code> の null pointer アクセスを修正するには、たとえば <a href="/ja/docs/Web/JavaScript/Reference/Operators/typeof">typeof</a> 演算子を使用できます。</p> + +<pre class="brush: js">if (typeof foo !== 'undefined') { + // Now we know that foo is defined, we are good to go. +}</pre> + +<h2 id="関連項目">関連項目</h2> + +<ul> + <li>{{jsxref("undefined")}}</li> + <li>{{jsxref("null")}}</li> +</ul> |
