diff options
author | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2021-08-17 11:37:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-17 11:37:07 +0900 |
commit | 98a7793a51bdbdeefb172842e677dca22eb779e5 (patch) | |
tree | f07cde27678193afe366832bd58c958657fadc6c /files/ja/web/javascript/reference/errors/no_non-null_object | |
parent | 6c30dec8016abec2fba8caf0bd07d0e145c37caf (diff) | |
parent | a28f6c8632ced6d91d311614d96ab643e5ef7058 (diff) | |
download | translated-content-98a7793a51bdbdeefb172842e677dca22eb779e5.tar.gz translated-content-98a7793a51bdbdeefb172842e677dca22eb779e5.tar.bz2 translated-content-98a7793a51bdbdeefb172842e677dca22eb779e5.zip |
Merge branch 'mdn:main' into 20210811-orphaned/Web/API/NavigatorLanguage
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 | 69 | ||||
-rw-r--r-- | files/ja/web/javascript/reference/errors/no_non-null_object/index.md | 73 |
2 files changed, 73 insertions, 69 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 deleted file mode 100644 index 93d167e25a..0000000000 --- a/files/ja/web/javascript/reference/errors/no_non-null_object/index.html +++ /dev/null @@ -1,69 +0,0 @@ ---- -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> - -<p>JavaScript の例外 "is not a non-null object" は、オブジェクトが何かを求めているのに提供されなかった場合に発生します。 {{jsxref("null")}} はオブジェクトではなく、動作しません。</p> - -<h2 id="Message">エラーメッセージ</h2> - -<pre class="brush: js">TypeError: Invalid descriptor for property {x} (Edge) -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="Property_descriptor_expected">プロパティディスクリプターが期待される場合</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_and_WeakSet_objects_require_object_keys"><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> diff --git a/files/ja/web/javascript/reference/errors/no_non-null_object/index.md b/files/ja/web/javascript/reference/errors/no_non-null_object/index.md new file mode 100644 index 0000000000..b548d38c6a --- /dev/null +++ b/files/ja/web/javascript/reference/errors/no_non-null_object/index.md @@ -0,0 +1,73 @@ +--- +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 +--- +{{JSSidebar("Errors")}} + +JavaScript の例外 "is not a non-null object" は、ある場所でオブジェクトが期待されているのに提供されなかった場合に発生します。 {{jsxref("null")}} はオブジェクトではなく、動作しません。 + +## エラーメッセージ + +```js +TypeError: Invalid descriptor for property {x} (Edge) +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) +``` + +## エラーの種類 + +{{jsxref("TypeError")}} + +## エラーの原因 + +ある場所でオブジェクトが期待されていますが、提供されませんでした。 {{jsxref("null")}} はオブジェクトではなく、動作しません。与えられた状況で適切なオブジェクトを提供しなければなりません。 + +## 例 + +## プロパティ記述子が求められている場合 + +{{jsxref("Object.create()")}} メソッドや {{jsxref("Object.defineProperty()")}} メソッド、{{jsxref("Object.defineProperties()")}} メソッドを使用するとき、省略可能な記述子の引数として、プロパティ記述子オブジェクトが想定されます。 (ただの数値など) オブジェクト以外のものを提供すると、エラーが発生します。 + +```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 +``` + +有効なプロパティ記述子はこのようになります。 + +```js example-good +Object.defineProperty({}, 'key', { value: 'foo', writable: false }); +``` + +## `WeakMap` および `WeakSet` オブジェクトにはオブジェクトキーが必要 + +{{jsxref("WeakMap")}} および {{jsxref("WeakSet")}} オブジェクトはオブジェクトをキーとして保持します。そのほかの型をキーとして使用できません。 + +```js example-bad +var ws = new WeakSet(); +ws.add('foo'); +// TypeError: "foo" is not a non-null object +``` + +代わりにオブジェクトを使用してください。 + +```js example-good +ws.add({foo: 'bar'}); +ws.add(window); +``` + +## 関連項目 + +- {{jsxref("Object.create()")}} +- {{jsxref("Object.defineProperty()")}}, {{jsxref("Object.defineProperties()")}} +- {{jsxref("WeakMap")}}, {{jsxref("WeakSet")}} |