mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 23:44:06 +08:00
126 lines
6.3 KiB
HTML
126 lines
6.3 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<p><code><strong>Math.min()</strong></code> 返回零个或更多个数值的最小值。</p>
|
||
<h2 id="Syntax" name="Syntax">语法</h2>
|
||
<pre><code class="language-javascript"><code>Math.min([<em>value1</em>[,<em>value2</em>, ...]]) </code></code></pre>
|
||
<h3 id="Parameters" name="Parameters">参数</h3>
|
||
<dl>
|
||
<dt><code>value1, value2, ...</code></dt>
|
||
<dd>一组数值</dd>
|
||
</dl>
|
||
<h3 id="返回值">返回值</h3>
|
||
<p>给定数值中最小的数。如果任一参数不能转换为数值,则返回<a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字(Not-A-Number)。"><code>NaN</code></a>。</p>
|
||
<h2 id="Description" name="Description">描述</h2>
|
||
<p>由于 <code>min</code> 是 <code>Math</code> 的静态方法,所以应该像这样使用:<code>Math.min()</code>,而不是作为你创建的 <code>Math</code> 实例的方法(Math 不是构造函数)。</p>
|
||
<p>如果没有参数,结果为<a href="Reference/Global_Objects/Infinity" title="全局属性 Infinity 是一个数值,表示无穷大。"><code>Infinity</code></a>。</p>
|
||
<p>如果有任一参数不能被转换为数值,结果为 <a href="Reference/Global_Objects/NaN" title="全局属性 NaN 的值表示不是一个数字(Not-A-Number)。"><code>NaN</code></a>。</p>
|
||
<h2 id="Examples" name="Examples">示例</h2>
|
||
<h3 id="Example:_Using_Math.min" name="Example:_Using_Math.min">使用 <code>Math.min()</code></h3>
|
||
<p>下例找出 x 和 y 的最小值,并把它赋值给 z:</p>
|
||
<pre><code class="language-js">var x = 10, y = -20;
|
||
var z = Math.min(x, y);
|
||
</code></pre>
|
||
<h3 id="Example.3A_Clipping_a_value_with_Math.min" name="Example.3A_Clipping_a_value_with_Math.min">使用 <code>Math.min()</code> 裁剪值(Clipping a value)</h3>
|
||
<p><code>Math.min</code> 经常用于裁剪一个值,以便使其总是小于或等于某个边界值。例如:</p>
|
||
<pre><code class="language-javascript">var x = f(foo);
|
||
|
||
if (x > boundary) {
|
||
x = boundary;
|
||
}</code></pre>
|
||
<p>可以写成:</p>
|
||
<pre><code class="language-js">var x = Math.min(f(foo), boundary);</code></pre>
|
||
<div>另外,<a href="Reference/Global_Objects/Math/max" title="Math.max() 函数返回一组数中的最大值。"><code>Math.max()</code></a> 也可以被用来以相似的方式裁剪一个值。</div>
|
||
<div> </div>
|
||
<h2 id="规范">规范</h2>
|
||
<table class="standard-table">
|
||
<tbody>
|
||
<tr>
|
||
<th scope="col">规范版本</th>
|
||
<th scope="col">规范状态</th>
|
||
<th scope="col">注解</th>
|
||
</tr>
|
||
<tr>
|
||
<td>ECMAScript 1st Edition. Implemented in JavaScript 1.0</td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td>初始定义。在 JavaScript 1.0 中实现。</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://www.ecma-international.org/ecma-262/5.1/#sec-15.8.2.12" hreflang="en" lang="en" rel="noopener">ECMAScript 5.1 (ECMA-262)<br/><small lang="zh-CN">Math.min</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-math.min" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Math.min</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-math.min" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">Math.min</small></a></td>
|
||
<td><span class="spec-Draft">Draft</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/Math/max" title="Math.max() 函数返回一组数中的最大值。"><code>Math.max()</code></a></li>
|
||
</ul>
|
||
</article> |