blob: b2ba78f9f099582f89211a0fe9e1e0afdc0ea4ab (
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
|
---
title: String.prototype.toString()
slug: Web/JavaScript/Reference/Global_Objects/String/toString
tags:
- JavaScript
- Method
- Prototype
- Reference
- String
translation_of: Web/JavaScript/Reference/Global_Objects/String/toString
---
<div>{{JSRef}}</div>
<p><strong><code>toString()</code></strong> メソッドは指定されたオブジェクトを表す文字列を返します。</p>
<div>{{EmbedInteractiveExample("pages/js/string-tostring.html")}}</div>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox notranslate"><code><var>str</var>.toString()</code></pre>
<h3 id="Return_value" name="Return_value">返値</h3>
<p>呼び出したオブジェクトを表す文字列です。</p>
<h2 id="Description" name="Description">詳細</h2>
<p>その {{jsxref("String")}} オブジェクトは、{{jsxref("Object")}} の <code>toString</code> メソッドを上書きします。つまり、{{jsxref("Object.prototype.toString()")}} を継承しません。{{jsxref("String")}} オブジェクトの <code>toString()</code> メソッドは、そのオブジェクトを表す文字列を返します( {{jsxref("String.prototype.valueOf()")}} と同等です)。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Using_toString" name="Using_toString()"><code>toString</code> メソッドを使う</h3>
<p>以下の例は、{{jsxref("String")}} オブジェクトを表す文字列の値を表示します。</p>
<pre class="brush: js notranslate">var x = new String('Hello world');
alert(x.toString()) // 'Hello world' を表示します
</pre>
<h2 id="Specifications" name="Specifications">仕様</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">仕様書</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-string.prototype.tostring', 'String.prototype.toString')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</h2>
<p>{{Compat("javascript.builtins.String.toString")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Object.prototype.toSource()")}}</li>
<li>{{jsxref("String.prototype.valueOf()")}}</li>
</ul>
|