语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -5,7 +5,7 @@
<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p>
<p>另请参见  <a href="Reference/Global_Objects/Array/find" title="find() 方法返回数组中满足提供的测试函数的第一个元素的值。否则返回 undefined。"><code>find()</code></a> 方法,它返回数组中找到的元素的<strong></strong>,而不是其索引。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><em>arr</em>.findIndex(<em>callback</em>[, <em>thisArg</em>])</code></pre>
<pre><code class="language-javascript"><code><em>arr</em>.findIndex(<em>callback</em>[, <em>thisArg</em>])</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>callback</code></dt>
@@ -31,7 +31,7 @@
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Testing_size_of_all_array_elements" name="Example:_Testing_size_of_all_array_elements">查找数组中首个质数元素的索引</h3>
<p><span style="line-height: inherit;">以下示例查找数组中素数的元素的索引(如果不存在素数,则返回-1</span></p>
<pre class="brush: js">function isPrime(element, index, array) {
<pre><code class="language-javascript">function isPrime(element, index, array) {
var start = 2;
while (start &lt;= Math.sqrt(element)) {
if (element % start++ &lt; 1) {
@@ -42,9 +42,9 @@
}
console.log([4, 6, 8, 12].findIndex(isPrime)); // -1, not found
console.log([4, 6, 7, 12].findIndex(isPrime)); // 2</pre>
console.log([4, 6, 7, 12].findIndex(isPrime)); // 2</code></pre>
<h2 id="Polyfill">Polyfill</h2>
<pre class="brush: js">// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
<pre><code class="language-javascript">// https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
if (!Array.prototype.findIndex) {
Object.defineProperty(Array.prototype, 'findIndex', {
value: function(predicate) {
@@ -88,7 +88,7 @@ if (!Array.prototype.findIndex) {
}
});
}
</pre>
</code></pre>
<p>如果您需要兼容不支持<code><a href="Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a></code>的JavaScript引擎那么最好不要对<code>Array.prototype</code>方法进行 polyfill 因为您无法使其成为不可枚举的。</p>
<p>使用此方法需要注意你是否在uc浏览器环境,如果你的页面在支付宝上使用尤其注意,因为支付宝使用的就是uc浏览器环境.</p>
<h2 id="规范">规范</h2>