2019-04-21 11:50:48 +08:00

137 lines
7.1 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.

This file contains Unicode characters that might be confused with other characters. 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>
<p><code><strong>Number.POSITIVE_INFINITY</strong></code> 属性表示正无穷大。</p>
<p>不必创建一个 <a href="Reference/Global_Objects/Number" title="JavaScript 的 Number 对象是经过封装的能让你处理数字值的对象。Number 对象由 Number() 构造器创建。"><code>Number</code></a> 实例,可使用 <code>Number.POSITIVE_INFINITY</code> 来访问该静态属性。</p>
<p></p><table class="standard-table">
<thead>
<tr>
<th class="header" colspan="2"><code>Number.POSITIVE_INFINITY</code> 属性的属性特性:</th>
</tr>
</thead>
<tbody>
<tr>
<td>writable</td>
<td>false</td>
</tr>
<tr>
<td>enumerable</td>
<td>false</td>
</tr>
<tr>
<td>configurable</td>
<td>false</td>
</tr>
</tbody>
</table><p></p>
<h2 id="描述">描述</h2>
<p><code>Number.POSITIVE_INFINITY</code> 的值同全局对象 <a href="Reference/Global_Objects/Infinity" title="全局属性 Infinity 是一个数值,表示无穷大。"><code>Infinity</code></a> 属性的值相同。</p>
<p>该值的表现同数学上的无穷大有点儿不同:</p>
<ul>
<li>任何正值,包括 <code>POSITIVE_INFINITY</code>,乘以 <code>POSITIVE_INFINITY</code><code>POSITIVE_INFINITY</code></li>
<li>任何负值,包括 <code>NEGATIVE_INFINITY</code>,乘以 <code>POSITIVE_INFINITY</code><code>NEGATIVE_INFINITY</code></li>
<li>0 乘以 <code>POSITIVE_INFINITY</code> 为 NaN。</li>
<li>NaN 乘以 <code>POSITIVE_INFINITY</code> 为 NaN。</li>
<li><code>POSITIVE_INFINITY</code> 除以 <code>NEGATIVE_INFINITY</code> 以外的任何负值为 <code>NEGATIVE_INFINITY</code></li>
<li><code>POSITIVE_INFINITY</code> 除以 <code>POSITIVE_INFINITY</code> 以外的任何正值为 <code>POSITIVE_INFINITY</code></li>
<li><code>POSITIVE_INFINITY</code> 除以 <code>NEGATIVE_INFINITY</code><code>POSITIVE_INFINITY</code> 为 NaN。</li>
<li>任何数除以 <code>POSITIVE_INFINITY</code> 为 0。</li>
</ul>
<p>You might use the <code>Number.POSITIVE_INFINITY</code> property to indicate an error condition that returns a finite number in case of success. Note, however, that <a href="Reference/Global_Objects/isFinite" title="该全局 isFinite() 函数用来判断被传入的参数值是否为一个有限数值finite number。在必要情况下参数会首先转为一个数值。"><code>isFinite</code></a> would be more appropriate in such a case.</p>
<h2 id="示例">示例</h2>
<p>下例中,赋值给变量 <code>bigNumber</code> 一个大于 JavaScript 中最大值的值。当 <code>if</code> 语句执行时,变量 <code>bigNumber</code> 值为 "<code>Infinity</code>" 因此在继续执行代码前,为变量 <code>bigNumber</code> 设置一个容易管理的值。</p>
<pre><code class="language-javascript">var bigNumber = Number.MAX_VALUE * 2
if (bigNumber == Number.POSITIVE_INFINITY) {
bigNumber = returnFinite();
}
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>ECMAScript 1st Edition. Implemented in JavaScript 1.1</td>
<td>Standard</td>
<td>Initial definition.</td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/5.1/#sec-15.7.3.6" hreflang="en" lang="en" rel="noopener">ECMAScript 5.1 (ECMA-262)<br/><small lang="zh-CN">Number.POSITIVE_INFINITY</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td> </td>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-number.positive_infinity" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Number.POSITIVE_INFINITY</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div><p></p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="See_also" name="See_also">相关链接</h2>
<ul>
<li><a href="Reference/Global_Objects/Number/NEGATIVE_INFINITY" title="Number.NEGATIVE_INFINITY 属性表示负无穷大。"><code>Number.NEGATIVE_INFINITY</code></a></li>
<li><a href="Reference/Global_Objects/Infinity" title="全局属性 Infinity 是一个数值,表示无穷大。"><code>Infinity</code></a></li>
<li><a href="Reference/Global_Objects/isFinite" title="该全局 isFinite() 函数用来判断被传入的参数值是否为一个有限数值finite number。在必要情况下参数会首先转为一个数值。"><code>isFinite</code></a></li>
</ul>
</article>