mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 15:34:05 +08:00
24 lines
1.8 KiB
HTML
24 lines
1.8 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<h2 id="信息">信息</h2>
|
||
<pre><code class="language-javascript">RangeError: repeat count must be non-negative (Firefox)
|
||
RangeError: Invalid count value (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/repeat" title="repeat() 构造并返回一个新字符串,该字符串包含被连接在一起的指定数量的字符串的副本。"><code>String.prototype.repeat()</code></a>方法。<span class="short_text" id="result_box" lang="zh-CN"><span>它有一个计数参数,表示重复该字符串的次数</span></span>。该参数必须在 0 及正 <a href="Reference/Global_Objects/Infinity" title="全局属性 Infinity 是一个数值,表示无穷大。"><code>Infinity</code></a> 之间,且不能为负数。该值的合法范围可以这样表示: [0, +∞)。</p>
|
||
<h2 id="示例">示例</h2>
|
||
<h3 id="无效的">无效的</h3>
|
||
<pre><code class="language-js example-bad">'abc'.repeat(-1); // RangeError </code></pre>
|
||
<h3 id="有效的">有效的</h3>
|
||
<pre><code class="language-js example-good">'abc'.repeat(0); // ''
|
||
'abc'.repeat(1); // 'abc'
|
||
'abc'.repeat(2); // 'abcabc'
|
||
'abc'.repeat(3.5); // 'abcabcabc' (count will be converted to integer)
|
||
</code></pre>
|
||
<h2 id="See_also">See also</h2>
|
||
<ul>
|
||
<li><a href="Reference/Global_Objects/String/repeat" title="repeat() 构造并返回一个新字符串,该字符串包含被连接在一起的指定数量的字符串的副本。"><code>String.prototype.repeat()</code></a></li>
|
||
</ul>
|
||
</article> |