2009-09-25 71 views
1

這是Mozilla的代碼在Mozilla的Array.prototype.indexOf問題上的代碼在Mozilla的Array.prototype.indexOf

if (!Array.prototype.indexOf) 
{ 
    Array.prototype.indexOf = function(elt) 
    { 
    var len = this.length >>> 0; // What does ">>>" do? 

    var from = Number(arguments[1]) || 0; 
    from = (from < 0) ? Math.ceil(from): Math.floor(from); 
    if (from < 0)from += len; 

    for (; from < len; from++) 
    { 
     if (from in this && this[from] === elt)return from; 
    } 
    return -1; 
    }; 
} 

我有些不明白的語法。
「>>>」在上面的代碼中做了什麼?

+1

精確複製:http://stackoverflow.com/questions/1385491/javascript-why-use-around-arguments-and-why-use-when-extracting-the – 2009-09-25 02:09:35

回答

6

這是一個無符號的右移 - 它們基本上是做爲轉換爲有效數組索引的一種非常快速的方式。

+0

+1 - 用於解釋他們爲什麼在此處使用它。 – 2009-09-25 00:28:48

1

這是我的信念

+0

Aye:請參閱:https:// developer .mozilla.org/En/Core_JavaScript_1.5_Reference/Operators/Bitwise_Operators – Wevah 2009-09-25 00:27:12