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/no_non-null_object | |
| 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/no_non-null_object')
| -rw-r--r-- | files/ja/web/javascript/reference/errors/no_non-null_object/index.html | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/errors/no_non-null_object/index.html b/files/ja/web/javascript/reference/errors/no_non-null_object/index.html new file mode 100644 index 0000000000..d602d95826 --- /dev/null +++ b/files/ja/web/javascript/reference/errors/no_non-null_object/index.html @@ -0,0 +1,66 @@ +--- +title: 'TypeError: "x" is not a non-null object' +slug: Web/JavaScript/Reference/Errors/No_non-null_object +tags: + - Error + - Errors + - JavaScript + - TypeError +translation_of: Web/JavaScript/Reference/Errors/No_non-null_object +--- +<div>{{JSSidebar("Errors")}}</div> + +<h2 id="メッセージ">メッセージ</h2> + +<pre class="syntaxbox">TypeError: "x" is not a non-null object (Firefox) +TypeError: Property description must be an object: "x" (Chrome) +TypeError: Invalid value used in weak set (Chrome) +</pre> + +<h2 id="エラータイプ">エラータイプ</h2> + +<p>{{jsxref("TypeError")}}</p> + +<h2 id="何がうまくいかなかったのか?">何がうまくいかなかったのか?</h2> + +<p>どこかでオブジェクトが期待されていますが、提供されませんでした。{{jsxref("null")}} はオブジェクトではなく、動作しません。与えられた状況で適切なオブジェクトを提供しなければなりません。</p> + +<h2 id="例">例</h2> + +<h3 id="プロパティディスクリプタが想定される">プロパティディスクリプタが想定される</h3> + +<p>{{jsxref("Object.create()")}} メソッドや {{jsxref("Object.defineProperty()")}} メソッド、{{jsxref("Object.defineProperties()")}} メソッドを使用するとき、省略可能なディスクリプタ引数として、プロパティディスクリプタオブジェクトが想定されます。(ただの数値のように) オブジェクトを提供しないと、エラーをスローします:</p> + +<pre class="brush: js example-bad">Object.defineProperty({}, 'key', 1); +// TypeError: 1 is not a non-null object + +Object.defineProperty({}, 'key', null); +// TypeError: null is not a non-null object +</pre> + +<p>有効なプロパティディスクリプタはこのようになります:</p> + +<pre class="brush: js example-good">Object.defineProperty({}, 'key', { value: 'foo', writable: false }); +</pre> + +<h3 id="WeakMap_オブジェクトと_WeakSet_オブジェクトはオブジェクトキーが必要"><code>WeakMap</code> オブジェクトと <code>WeakSet</code> オブジェクトはオブジェクトキーが必要</h3> + +<p>{{jsxref("WeakMap")}} オブジェクトと {{jsxref("WeakSet")}} オブジェクトはオブジェクトキーを保持します。そのほかの型をキーとして使用できません。</p> + +<pre class="brush: js example-bad">var ws = new WeakSet(); +ws.add('foo'); +// TypeError: "foo" is not a non-null object</pre> + +<p>代わりにオブジェクトを使用します:</p> + +<pre class="brush: js example-good">ws.add({foo: 'bar'}); +ws.add(window); +</pre> + +<h2 id="関連項目">関連項目</h2> + +<ul> + <li>{{jsxref("Object.create()")}}</li> + <li>{{jsxref("Object.defineProperty()")}}、{{jsxref("Object.defineProperties()")}}</li> + <li>{{jsxref("WeakMap")}}、{{jsxref("WeakSet")}}</li> +</ul> |
