Files
uTools-Manuals/docs/javascript/Reference/Errors/Not_a_codepoint.html
T
fofolee 38dcd51d8a v0.0.2
2019-04-21 11:50:48 +08:00

33 lines
2.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<article id="wikiArticle">
<div></div>
<h2 id="错误信息">错误信息</h2>
<pre><code class="language-javascript">RangeError: {0} is not a valid code point (Firefox)
RangeError: Invalid code point {0} (Chrome)
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/RangeError" title="RangeError对象标明一个错误,当一个值不在其所允许的范围或者集合中。"><code>RangeError</code></a></p>
<h2 id="什么地方出错了?">什么地方出错了?</h2>
<p> <a href="Reference/Global_Objects/String/fromCodePoint" title="String.fromCodePoint() 静态方法返回使用指定的代码点序列创建的字符串。"><code>String.fromCodePoint()</code></a> 这个方法只能接受有效的码位(code point) 。</p>
<p>码位( <a class="external" href="https://en.wikipedia.org/wiki/Code_point" rel="noopener">code point</a>)是组成码空间(或代码页)的数值,范围是 0 到 0x10FFFF。</p>
<p> <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字(Not-A-Number)。"><code>NaN</code></a>,负整数(-1),非整数(3.14),或编号大于0x10FFFF (1114111) 的字符,无法使用该方法。</p>
<h2 id="范例">范例</h2>
<h3 id="无效的例子">无效的例子</h3>
<pre><code class="language-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</code></pre>
<h3 id="有效的例子">有效的例子</h3>
<pre><code class="language-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"
</code></pre>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="Reference/Global_Objects/String/fromCodePoint" title="String.fromCodePoint() 静态方法返回使用指定的代码点序列创建的字符串。"><code>String.fromCodePoint()</code></a></li>
</ul>
</article>