aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/javascript/reference/global_objects/string/quote/index.html
blob: 2a074faf32a5dcb9bef2fb497909396c437c8186 (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
---
title: String.prototype.quote()
slug: Web/JavaScript/Reference/Global_Objects/String/quote
tags:
  - String
  - String Methods
translation_of: Archive/Web/JavaScript/String.quote
---
<div>{{JSRef}} {{obsolete_header("37")}} {{non-standard_header}}</div>

<p>特殊文字をエスケープシーケンスで置換しダブル・クォーテーション(<code>"</code>)でラップした文字列のコピーを返します。</p>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox"><code><em>str</em>.quote()</code></pre>

<h3 id="Return_value">Return value</h3>

<p>A new string representing the original string wrapped in double-quotes, with any special characters escaped.</p>

<h2 id="Examples" name="Examples"></h2>

<p>In the table below thequote()method replaces any special characters and wraps the strings in double-quotes. Also note the third column where a wrapped {{jsxref("Global_Objects/eval", "eval()")}} evaluates the escape sequences again.</p>

<table class="fullwidth-table" style="width: 100%;">
 <thead>
  <tr>
   <th class="header" scope="col"><code>str</code></th>
   <th class="header" scope="col"><code>str.quote()</code></th>
   <th class="header" scope="col"><code><a href="/ja/docs/JavaScript/Reference/Global_Objects/eval" title="JavaScript/Reference/Global_Objects/eval">eval</a>( str.quote() )</code></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td><code>Hello world!</code></td>
   <td><code>"Hello world!"</code></td>
   <td><code>Hello world!</code></td>
  </tr>
  <tr>
   <td><code>Hello<br>
            world!</code></td>
   <td><code>"Hello\n\tworld!"</code></td>
   <td><code>Hello<br>
            world!</code></td>
  </tr>
  <tr>
   <td><code>" \ — '</code></td>
   <td><code>"\" \\ \u2014 '"</code></td>
   <td><code>" \ — '</code></td>
  </tr>
 </tbody>
</table>

<h2 id="仕様">仕様</h2>

<p>Not part of any standard. Implemented in JavaScript 1.3.</p>

<h2 id="ポリフィル">ポリフィル</h2>

<pre class="syntaxbox"><code>if (!String.prototype.quote)
    String.prototype.quote = function(){
        return JSON.stringify( this ); // since IE8
</code>    }</pre>

<h2 id="ブラウザ互換性情報">ブラウザ互換性情報</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

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

<h2 id="関連情報">関連情報</h2>

<ul>
 <li>{{jsxref("JSON.stringify()")}}</li>
</ul>