ReferenceError
当引用当前作用域中不存在(或尚未初始化)的变量时,ReferenceError 对象表示错误。
¥The ReferenceError object represents an error when a variable that doesn't exist (or hasn't yet been initialized) in the current scope is referenced.
ReferenceError 是 serializable object,因此可以使用 structuredClone() 进行克隆,或者使用 postMessage() 在 工人 之间进行复制。
¥ReferenceError is a serializable object, so it can be cloned with structuredClone() or copied between Workers using postMessage().
ReferenceError 是 Error 的子类。
¥ReferenceError is a subclass of Error.
构造函数
实例属性
¥Instance properties
还从其父级 Error 继承实例属性。
¥Also inherits instance properties from its parent Error.
这些属性在 ReferenceError.prototype 上定义并由所有 ReferenceError 实例共享。
¥These properties are defined on ReferenceError.prototype and shared by all ReferenceError instances.
ReferenceError.prototype.constructor-
创建实例对象的构造函数。对于
ReferenceError实例,初始值为ReferenceError构造函数。 ReferenceError.prototype.name-
表示错误类型的名称。对于
ReferenceError.prototype.name,初始值为"ReferenceError"。
实例方法
示例
捕获引用错误
创建引用错误
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-native-error-types-used-in-this-standard-referenceerror |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also