aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/math/sign
diff options
context:
space:
mode:
authorIrvin <irvinfly@gmail.com>2022-02-16 02:07:31 +0800
committerIrvin <irvinfly@gmail.com>2022-02-16 02:35:54 +0800
commitd9e9adb5f80a819fe46349bcf6d1faec734b09cd (patch)
treee856dc5e31aad0a7d5e8c2f98c9ee139d9569a86 /files/zh-cn/web/javascript/reference/global_objects/math/sign
parent7c2556fe79c44d7c31108b8c8b048d2b7704a95e (diff)
downloadtranslated-content-d9e9adb5f80a819fe46349bcf6d1faec734b09cd.tar.gz
translated-content-d9e9adb5f80a819fe46349bcf6d1faec734b09cd.tar.bz2
translated-content-d9e9adb5f80a819fe46349bcf6d1faec734b09cd.zip
remove span tag in zh-CN
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/math/sign')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html12
1 files changed, 6 insertions, 6 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html
index ca7678c9f0..9c41082511 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/math/sign/index.html
@@ -50,12 +50,12 @@ Math.sign(); // NaN
<h2 id="Compatibility" name="Compatibility">Polyfill</h2>
-<pre class="brush: js language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">sign<span class="punctuation token">(</span></span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span>
- x <span class="operator token">=</span> <span class="operator token">+</span>x<span class="comment token"> ;// convert to a number
-</span> <span class="keyword token">if</span> <span class="punctuation token">(</span>x <span class="operator token">===</span> <span class="number token">0</span> <span class="operator token">||</span> <span class="function token">isNaN<span class="punctuation token">(</span></span>x<span class="punctuation token">)</span><span class="punctuation token">)</span>
- <span class="keyword token">return</span> x;
- <span class="keyword token">return</span> x <span class="operator token">&gt;</span> <span class="number token">0</span> <span class="operator token">?</span> <span class="number token">1</span> <span class="punctuation token">:</span> <span class="operator token">-</span><span class="number token">1;</span>
-<span class="punctuation token">}</span></code></pre>
+<pre class="brush: js language-js"><code class="language-js">function sign(x) {
+ x = +x ;// convert to a number
+ if (x === 0 || isNaN(x))
+ return x;
+ return x &gt; 0 ? 1 : -1;
+}</code></pre>
<p> </p>