概述
message 属性是有关错误信息,人类易读的(human-readable)描述。
描述
如果该属性已经被设置,则该属性包含了错误的一个简短描述。SpiderMonkey 大量应用 message 属性在异常方面。 message 属性结合 Error.prototype.toString() 方法用来创建错误的字符串形式。
默认情况下,message 属性是一个空字符串,但是可以通过指定一段信息作为 Error constructor 的第一个参数创建一个实例来改变该属性值。
示例
例子:抛出一个自定义错误
var e = new Error("Could not parse input"); // e.message is "Could not parse input"
throw e;
规范
| 规范版本 | 规范状态 | 注解 |
|---|---|---|
| ECMAScript 1st Edition. | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) Error.prototype.message |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) Error.prototype.message |
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) |