aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/evalerror/index.html
blob: 85eebfa1cec35e96962b9d7e422242fb706e65ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
title: EvalError
slug: Web/JavaScript/Reference/Global_Objects/EvalError
translation_of: Web/JavaScript/Reference/Global_Objects/EvalError
---
<div>{{JSRef}}</div>

<p>本对象代表了一个关于 <a href="/en/Core_JavaScript_1.5_Reference/Global_Functions/eval" title="en/Core_JavaScript_1.5_Reference/Global_Functions/eval">eval</a> 函数的错误.此异常不再会被JavaScript抛出,但是EvalError对象仍然保持兼容性.</p>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="syntaxbox"><code>new EvalError([<var>message</var>[, <var>fileName</var>[, <var>lineNumber</var>]]])</code></pre>

<h3 id="Parameters" name="Parameters">参数</h3>

<dl>
 <dt>message</dt>
 <dd>可选参数.人类可阅读的关于错误的描述.</dd>
</dl>

<dl>
 <dt>fileName(非标准)</dt>
 <dd>可选参数.代码中导致异常的文件的文件名.</dd>
</dl>

<dl>
 <dt>lineNumber(非标准)</dt>
 <dd>可选参数.代码中导致异常的代码的行号.</dd>
</dl>

<h2 id="Properties" name="Properties">属性</h2>

<dl>
 <dt><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype" title="en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype">prototype</a></dt>
 <dd>允许向EvalError对象中添加自定义属性.</dd>
</dl>

<h2 id="Methods" name="Methods">方法</h2>

<p>全局的EvalError对象本身不包含任何方法, 然而它通过原型链继承了一些方法.</p>

<h2 id="EvalError_实例"><code>EvalError</code> 实例</h2>

<h3 id="属性">属性</h3>

<p>{{page('/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/EvalError/prototype', 'Properties')}}</p>

<h3 id="方法">方法</h3>

<p>{{page('/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/EvalError/prototype', 'Methods')}}</p>

<h2 id="例子">例子</h2>

<p><code>EvalError</code> 不在当前ECMAScript规范中使用,因此不会被运行时抛出. 但是对象本身仍然与规范的早期版本向后兼容.</p>

<h3 id="创建_EvalError">创建 <code>EvalError</code></h3>

<pre><code>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"
}</code></pre>

<h2 id="规范">规范</h2>

<table>
 <tbody>
  <tr>
   <th scope="col">规范</th>
   <th scope="col">状态</th>
   <th scope="col">注释</th>
  </tr>
  <tr>
   <td>{{SpecName('ES3')}}</td>
   <td>{{Spec2('ES3')}}</td>
   <td>初始定义.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.11.6.1', 'EvalError')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>本规范中未使用. 为了保持向后兼容.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-evalerror', 'EvalError')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>本规范中未使用. 为了保持向后兼容.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard-evalerror', 'EvalError')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div class="hidden">
<p>该页面中的兼容性表格由结构化的数据生成。如果有意向贡献数据,请查看 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并发起 pull request。</p>
</div>

<p>{{Compat("javascript.builtins.EvalError")}}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Error" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Error">Error</a></li>
 <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Functions/eval" title="en/Core_JavaScript_1.5_Reference/Global_Functions/eval">eval</a></li>
 <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype" title="en/Core_JavaScript_1.5_Reference/Global_Objects/EvalError/prototype">EvalError.prototype</a></li>
</ul>