概述

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  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

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)

相关链接

文档标签和贡献者

此页面的贡献者: yenshen, teoli, ziyunfei
最后编辑者: yenshen,