A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/No_non-null_object below:

TypeError: "x" is not a non-null object - JavaScript

TypeError: "x" is not a non-null object 提示信息
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)
错误类型 哪里出错了?

在期待出现对象类型的值的地方而没有提供。null 不是对象类型,因此不起作用。必须在给定的场景下提供一个合适的对象。

示例 期望的属性描述器

当使用诸如 Object.create() 或 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 对象需要对象类型的键

WeakMap 和 WeakSet 对象只能存储对象类型的键,而不能使用其他类型的。

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

用对象类型的值来替换:

ws.add({ foo: "bar" });
ws.add(window);
相关内容

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4