From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/errors/no_non-null_object/index.html | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 files/ja/web/javascript/reference/errors/no_non-null_object/index.html (limited to 'files/ja/web/javascript/reference/errors/no_non-null_object') 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 +--- +
{{JSSidebar("Errors")}}
+ +

メッセージ

+ +
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()")}} メソッドを使用するとき、省略可能なディスクリプタ引数として、プロパティディスクリプタオブジェクトが想定されます。(ただの数値のように) オブジェクトを提供しないと、エラーをスローします:

+ +
Object.defineProperty({}, 'key', 1);
+// TypeError: 1 is not a non-null object
+
+Object.defineProperty({}, 'key', null);
+// TypeError: null is not a non-null object
+
+ +

有効なプロパティディスクリプタはこのようになります:

+ +
Object.defineProperty({}, 'key', { value: 'foo', writable: false });
+
+ +

WeakMap オブジェクトと WeakSet オブジェクトはオブジェクトキーが必要

+ +

{{jsxref("WeakMap")}} オブジェクトと {{jsxref("WeakSet")}} オブジェクトはオブジェクトキーを保持します。そのほかの型をキーとして使用できません。

+ +
var ws = new WeakSet();
+ws.add('foo');
+// TypeError: "foo" is not a non-null object
+ +

代わりにオブジェクトを使用します:

+ +
ws.add({foo: 'bar'});
+ws.add(window);
+
+ +

関連項目

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