name
属性表示error类型的名称.初始值为"Error".
默认情况下,Error
对象的name
属性值为"Error".name属性和
message
属性一起,通过调用Error.prototype.toString()
方法,会作为最后异常信息的字符串表示.
var e = new Error("Malformed input"); // e.name默认是"Error"
e.name = "ParseError"; // 修改之后,e.toString()会成为下面这样的字符串
throw e; // "ParseError: Malformed input"
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition. | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262) Error.prototype.name |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Error.prototype.name |
Standard |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |