diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/not_a_codepoint | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/errors/not_a_codepoint')
-rw-r--r-- | files/zh-cn/web/javascript/reference/errors/not_a_codepoint/index.html | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/not_a_codepoint/index.html b/files/zh-cn/web/javascript/reference/errors/not_a_codepoint/index.html new file mode 100644 index 0000000000..769e6daa0c --- /dev/null +++ b/files/zh-cn/web/javascript/reference/errors/not_a_codepoint/index.html @@ -0,0 +1,51 @@ +--- +title: 'RangeError: argument is not a valid code point' +slug: Web/JavaScript/Reference/Errors/Not_a_codepoint +translation_of: Web/JavaScript/Reference/Errors/Not_a_codepoint +--- +<div>{{jsSidebar("Errors")}}</div> + +<h2 id="错误信息">错误信息</h2> + +<pre class="syntaxbox">RangeError: {0} is not a valid code point (Firefox) +RangeError: Invalid code point {0} (Chrome) +</pre> + +<h2 id="错误类型">错误类型</h2> + +<p>{{jsxref("RangeError")}}</p> + +<h2 id="什么地方出错了?">什么地方出错了?</h2> + +<p> {{jsxref("String.fromCodePoint()")}} 这个方法只能接受有效的码位(code point) 。</p> + +<p>码位( <a href="https://en.wikipedia.org/wiki/Code_point">code point</a>)是组成码空间(或代码页)的数值,范围是 0 到 0x10FFFF。</p> + +<p> {{jsxref("NaN")}},负整数(-1),非整数(3.14),或编号大于0x10FFFF (1114111) 的字符,无法使用该方法。</p> + +<h2 id="范例">范例</h2> + +<h3 id="无效的例子">无效的例子</h3> + +<pre class="brush: js example-bad">String.fromCodePoint('_'); // RangeError +String.fromCodePoint(Infinity); // RangeError +String.fromCodePoint(-1); // RangeError +String.fromCodePoint(3.14); // RangeError +String.fromCodePoint(3e-2); // RangeError +String.fromCodePoint(NaN); // RangeError</pre> + +<h3 id="有效的例子">有效的例子</h3> + +<pre class="brush: js example-good">String.fromCodePoint(42); // "*" +String.fromCodePoint(65, 90); // "AZ" +String.fromCodePoint(0x404); // "\u0404" +String.fromCodePoint(0x2F804); // "\uD87E\uDC04" +String.fromCodePoint(194564); // "\uD87E\uDC04" +String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07" +</pre> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{jsxref("String.fromCodePoint()")}}</li> +</ul> |