escape()
is not strictly deprecated (as in "removed from the Web standards"), it is defined in
Annex B
of the ECMA-262 standard, whose introduction states:
… All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. …
… Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. …
escape()
function computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.
注意:
This function was used mostly for URL queries (the part of a URL following
?
)—
not
for escaping ordinary String literals, which use the format "
\x
HH
". (
HH
are two hexadecimal digits, and the form
\x
HH
\x
HH
is used for higher-plane Unicode characters.)
Escaped characters in String literals can be expanded by replacing the
\x
with
%
, then using the
decodeURIComponent()
函数。
escape(str)
str
A string to be encoded.
A new string in which certain characters have been escaped.
escape
function is a property of the
全局对象
. Special characters are encoded with the exception of:
@*_+-./
The hexadecimal form for characters, whose code unit value is
0xFF
or less, is a two-digit escape sequence:
%
xx
. For characters with a greater code unit, the four-digit format
%
u
xxxx
被使用。
escape('abc123'); // "abc123"
escape('äöü'); // "%E4%F6%FC"
escape('ć'); // "%u0107"
// special characters
escape('@*_+-./'); // "@*_+-./"
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'escape' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
escape
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持
弃用。不要用于新网站。