blob: 0f96a64a5eddc2507f730ab41ad90d6ec6b11aed (
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
|
---
title: escape()
slug: Web/JavaScript/Reference/Global_Objects/escape
tags:
- Deprecated
- JavaScript
- Method
- メソッド
- 非推奨
translation_of: Web/JavaScript/Reference/Global_Objects/escape
---
<div>{{jsSidebar("Objects")}}</div>
<div class="warning"><strong>警告:</strong> <code>escape()</code> は厳密には非推奨ではありませんが (「ウェブ標準から削除された」という意味で)、ECMA-262 標準の <a href="https://www.ecma-international.org/ecma-262/9.0/index.html#sec-additional-ecmascript-features-for-web-browsers">Annex B</a> で定義されており、その導入部には次のように書かれています。
<blockquote>… この付属書で規定されているすべての言語機能と動作は、1つ以上の望ましくない特性を持ち、レガシーな使用例がない場合は、この仕様から削除されます。…<br>
… プログラマは、新しい ECMAScript コードを書くときに、これらの機能や動作の存在を使用したり、仮定したりしてはいけません。…</blockquote>
</div>
<p><span class="seoSummary">The <code><strong>escape()</strong></code> 関数は、特定の文字を16進数のエスケープシーケンスで置き換えた新しい文字列を計算します。</span></p>
<div class="blockIndicator note">
<p><strong>メモ:</strong> この関数は、主に URL クエリ (URL の <code>?</code> に続く部分) に使われていました。 — "<code>\x<var>HH</var></code>" の形式を使用して、ふつうの文字列リテラルをエスケープするためのものでは<em>ありません</em>。 (HHは2桁の16進数であり、より高い面の Unicode 文字には「\xHH\xHHxHH」という形式が使われます。)</p>
<p>文字列リテラル内のエスケープされた文字は、 <code>\x</code> を <code>%</code> に置き換えてから、 <code>decodeURIComponent()</code> 関数を使用することで展開することができます。</p>
</div>
<h2 id="Syntax" name="Syntax">構文</h2>
<pre class="syntaxbox">escape(<var>str</var>)</pre>
<h3 id="Parameters" name="Parameters">引数</h3>
<dl>
<dt><code><var>str</var></code></dt>
<dd>エンコードする文字列。</dd>
</dl>
<h3 id="Return_value" name="Return_value">返値</h3>
<p>特定の文字がエスケープされた新しい文字列。</p>
<h2 id="Description" name="Description">解説</h2>
<p><code>escape</code> 関数は<em>グローバルオブジェクト</em>のプロパティです。特殊文字は <code>@*_+-./</code> 以外の文字が符号化されます。</p>
<p>文字の16進数形式として、文字コードの値が <code>0xFF</code> 以下になる文字は 2 桁のエスケープシーケンス <code>%<var>xx</var></code> が、それ以上の場合は 4 桁のエスケープシーケンス <code>%<strong>u</strong><var>xxxx</var></code><code>%<strong>u</strong><var>xxxx</var></code> が使われます。</p>
<h2 id="Examples" name="Examples">例</h2>
<pre class="brush: js">escape('abc123'); // "abc123"
escape('äöü'); // "%E4%F6%FC"
escape('ć'); // "%u0107"
// 特殊文字
escape('@*_+-./'); // "@*_+-./"</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ESDraft', '#sec-escape-string', 'escape')}}</td>
</tr>
</tbody>
</table>
<div class="hidden">リファレンスページにポリフィルを追加しないでください。詳しくは、 <a href="https://discourse.mozilla.org/t/mdn-rfc-001-mdn-wiki-pages-shouldnt-be-a-distributor-of-polyfills/24500">https://discourse.mozilla.org/t/mdn-rfc-001-mdn-wiki-pages-shouldnt-be-a-distributor-of-polyfills/24500</a> を参照してください。</div>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
<p>{{Compat("javascript.builtins.escape")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("encodeURI")}}</li>
<li>{{jsxref("encodeURIComponent")}}</li>
<li>{{jsxref("unescape")}}</li>
</ul>
|