aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/negative_repetition_count
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/negative_repetition_count
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-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/negative_repetition_count')
-rw-r--r--files/zh-cn/web/javascript/reference/errors/negative_repetition_count/index.html45
1 files changed, 45 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/negative_repetition_count/index.html b/files/zh-cn/web/javascript/reference/errors/negative_repetition_count/index.html
new file mode 100644
index 0000000000..780bdabcf4
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/errors/negative_repetition_count/index.html
@@ -0,0 +1,45 @@
+---
+title: 'RangeError: repeat count must be non-negative'
+slug: Web/JavaScript/Reference/Errors/Negative_repetition_count
+tags:
+ - Errors
+ - JavaScript
+ - RangeError
+ - 错误
+translation_of: Web/JavaScript/Reference/Errors/Negative_repetition_count
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="信息">信息</h2>
+
+<pre class="syntaxbox">RangeError: repeat count must be non-negative (Firefox)
+RangeError: Invalid count value (Chrome)
+</pre>
+
+<h2 id="错误类型">错误类型</h2>
+
+<p>{{jsxref("RangeError")}}</p>
+
+<h2 id="发生了什么">发生了什么?</h2>
+
+<p>代码中使用了 {{jsxref("String.prototype.repeat()")}}方法。<span class="short_text" id="result_box" lang="zh-CN"><span>它有一个计数参数,表示重复该字符串的次数</span></span>。该参数必须在 0 及正 {{jsxref("Infinity")}} 之间,且不能为负数。该值的合法范围可以这样表示: [0, +∞)。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="无效的">无效的</h3>
+
+<pre class="brush: js example-bad">'abc'.repeat(-1); // RangeError </pre>
+
+<h3 id="有效的">有效的</h3>
+
+<pre class="brush: 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)
+</pre>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{jsxref("String.prototype.repeat()")}}</li>
+</ul>