EvalError
本对象代表了一个关于 eval函数的错误.此异常不再会被JavaScript抛出,但是EvalError对象仍然保持兼容性.
语法
new EvalError([message[, fileName[, lineNumber]]])
参数
message可选参数.人类可阅读的关于错误的描述.fileName(非标准)可选参数.代码中导致异常的文件的文件名.lineNumber(非标准)可选参数.代码中导致异常的代码的行号.
属性
prototype允许向EvalError对象中添加自定义属性.
方法
全局的EvalError对象本身不包含任何方法, 然而它通过原型链继承了一些方法.
EvalError
实例
属性
EvalError.prototype.constructor
指定创建实例原型的函数.
EvalError.prototype.message
错误信息. 从 ECMA-262 开始EvalError
提供 message
(继承自Error.prototype.message
)属性, 详见 SpiderMonkey.
EvalError.prototype.name
错误名称.继承自Error
.
EvalError.prototype.fileName
引发错误的文件路径. 继承自Error
.
EvalError.prototype.lineNumber
引发错误所在行.继承自 Error
.
EvalError.prototype.columnNumber
引发错误所在的列. 继承自Error
.
方法
虽然EvalError
自己的属性方法较少, 但是通过原型链继承了很多有用的方法.
示例
EvalError
不在当前ECMAScript规范中使用,因此不会被运行时抛出. 但是对象本身仍然与规范的早期版本向后兼容.
创建 EvalError
try {
throw new EvalError('Hello', 'someFile.js', 10);
} catch (e) {
console.log(e instanceof EvalError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "EvalError"
console.log(e.fileName); // "someFile.js"
console.log(e.lineNumber); // 10
console.log(e.columnNumber); // 0
console.log(e.stack); // "@Scratchpad/2:2:9\n"
}
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262)The definition of 'EvalError' in that specification. | Standard | Not used in this specification. Present for backward compatibility. |
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'EvalError' in that specification. | Standard | Not used in this specification. Present for backward compatibility. |
ECMAScript Latest Draft (ECMA-262)The definition of 'EvalError' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com