【问题标题】:What means >>> character in javascript [duplicate]javascript中的>>>字符是什么意思[重复]
【发布时间】:2014-06-19 07:44:39
【问题描述】:

今天我在 MDN 上阅读了一些文章,发现了一些新的东西。在第 11 行的 link 中,我发现了一些类似的东西:

 var t = Object( this ), len = t.length >>> 0, k = 0, value;

完整的代码是:

if ( 'function' !== typeof Array.prototype.reduce ) {
 Array.prototype.reduce = function( callback /*, initialValue*/ ) {
'use strict';
if ( null === this || 'undefined' === typeof this ) {
  throw new TypeError(
     'Array.prototype.reduce called on null or undefined' );
}
if ( 'function' !== typeof callback ) {
  throw new TypeError( callback + ' is not a function' );
}
var t = Object( this ), len = t.length >>> 0, k = 0, value;
if ( arguments.length >= 2 ) {
  value = arguments[1];
} else {
  while ( k < len && ! k in t ) k++; 
  if ( k >= len )
    throw new TypeError('Reduce of empty array with no initial value');
  value = t[ k++ ];
}
for ( ; k < len ; k++ ) {
  if ( k in t ) {
     value = callback( value, t[k], k, t );
  }
}
return value;
};
}

那么第 11 行中的 &gt;&gt;&gt; 字符是什么意思。

【问题讨论】:

标签: javascript ecmascript-5 ecma262


【解决方案1】:

&gt;&gt;&gt; 是零填充右移运算符。 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Unsigned_right_shift

为了使用运算符,JavaScript 必须将参数转换为整数。移位 0 位对整数没有影响,因此在本程序中移位仅用于确保类型正确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    • 2019-12-20
    • 2019-02-26
    • 2014-12-31
    • 2015-07-15
    • 2018-07-17
    • 2011-04-16
    相关资源
    最近更新 更多