--- title: ErrorEvent slug: Web/API/ErrorEvent tags: - API - Event translation_of: Web/API/ErrorEvent --- <p>{{APIRef("HTML DOM")}}</p> <p><strong><code>ErrorEvent</code></strong> 事件对象在脚本发生错误时产生,它可以提供发生错误的脚本文件的文件名,以及发生错误时所在的行号等信息。</p> <h2 id="属性">属性</h2> <p>除了从 {{domxref("Event")}} 接口继承来的属性外,还有下面这些自身属性。</p> <dl> <dt>{{domxref("ErrorEvent.prototype.message")}} {{readonlyInline}}</dt> <dd>一个{{domxref("DOMString","字符串")}},包含了所发生错误的描述信息。</dd> <dt>{{domxref("ErrorEvent.prototype.filename")}} {{readonlyInline}}</dt> <dd>一个 {{domxref("DOMString","字符串")}},包含了发生错误的脚本文件的文件名。</dd> <dt>{{domxref("ErrorEvent.prototype.lineno")}} {{readonlyInline}}</dt> <dd>一个数字,包含了错误发生时所在的行号。</dd> <dt>{{domxref("ErrorEvent.prototype.colno")}} {{readonlyInline}}</dt> <dd>一个数字,包含了错误发生时所在的列号。</dd> <dt>{{domxref("ErrorEvent.prototype.error")}} {{readonlyInline}} {{experimental_inline}}</dt> <dd>发生错误时所抛出的 {{jsxref("Error")}} 对象。</dd> </dl> <h2 id="构造函数">构造函数</h2> <dl> <dt>{{domxref("ErrorEvent.ErrorEvent", "ErrorEvent()")}}</dt> <dd>根据传入的参数构造 <code>ErrorEvent</code> 实例。</dd> </dl> <h2 id="方法">方法</h2> <p>除了从 {{domxref("Event")}} 接口继承来的方法外,没有其他方法。</p> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">规范名称</th> <th scope="col">规范状态</th> <th scope="col">备注</th> </tr> </thead> <tbody> <tr> <td>{{ SpecName('HTML WHATWG', 'webappapis.html#the-errorevent-interface', 'ErrorEvent') }}</td> <td>{{ Spec2('HTML WHATWG') }}</td> <td>增加了 <code>error</code> 属性以及其构造函数的第五个参数</td> </tr> <tr> <td>{{ SpecName('HTML5 W3C', 'webappapis.html#the-errorevent-interface', 'ErrorEvent') }}</td> <td>{{ Spec2('HTML5 W3C') }}</td> <td>最初规范</td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("api.ErrorEvent")}}</p> <h2 id="相关链接">相关链接</h2> <ul> <li><a href="/zh-CN/docs/Web/Guide/Performance/Using_web_workers">使用 web worker</a>, most likely objects to raise such an event</li> </ul>