blob: 6412e49f5efefa3b9e9a7e4d9737cc5010b7884a (
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
|
---
title: Error.prototype.name
slug: Web/JavaScript/Reference/Global_Objects/Error/name
tags:
- JavaScript
- Property
- Prototype
translation_of: Web/JavaScript/Reference/Global_Objects/Error/name
---
<div>{{JSRef}}</div>
<p><code><strong>name</strong></code> プロパティは、エラーの種類の名称を表します。初期値は "Error" です。</p>
<h2 id="Description" name="Description">解説</h2>
<p>既定で {{jsxref("Error")}} インスタンスには "Error" という名称が与えられます。 <code>name</code> プロパティは {{jsxref("Error.prototype.message", "message")}} プロパティに加えて、 Error の文字列表現を生成するため、{{jsxref("Error.prototype.toString()")}} メソッドにより使用されます。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Throwing_a_custom_error" name="Throwing_a_custom_error">独自のエラーを発生させる</h3>
<pre class="brush: js notranslate">var e = new Error('Malformed input'); // e.name は 'Error'
e.name = 'ParseError';
throw e;
// e.toString() would return 'ParseError: Malformed input'
</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">仕様書</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-error.prototype.name', 'Error.prototype.name')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<div>
<p>{{Compat("javascript.builtins.Error.name")}}</p>
</div>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Error.prototype.message")}}</li>
<li>{{jsxref("Error.prototype.toString()")}}</li>
</ul>
|