什么是">>>"运营商JS? [英] What is ">>>" operator in JS?
问题描述
可能重复:结果
JavaScript的>>>运营商?结果
JavaScript的三重比更大
块引用>发现这个操作符code这样的行:
VAR T =对象(本),
LEN = t.length>>> 0;这是什么意思运营商?
全部code如下。这是JS的code
部分
方法:如果(!Array.prototype.some){
Array.prototype.some =函数(FUN / *,* thisp /){
使用严格的; 如果(这种== NULL)抛出新的TypeError(); 变种T =对象(本),
LEN = t.length>>> 0; 如果(typeof运算的乐趣=功能!)抛出新的TypeError(); 变种thisp =参数[1]; 对于(VAR I = 0; I< LEN,我++){
如果(我在T&放大器;&安培; fun.call(thisp,T [I],I,T))
返回true;
} 返回false;
};
}
解决方案
>>>
是一个右移的无符号扩展的如果您使用
>>
上一个负数运营商,其结果也将是负的,因为原来的符号位被复制到所有的新位。随着>>方式>
零将代替被复制在这个特定的情况下,它只是被用来作为一种方法来在
长度
字段限制为无符号31位整数,或者换句话说,以铸造JavaScript的原生IEEE754 双规数到一个整数。Possible Duplicate:
javascript >>> operator?
JavaScript triple greater thanFound this operator in such line of code:
var t = Object(this), len = t.length >>> 0;
What does this operator mean?
Full code is below. It is the code of JS
some
method:if (!Array.prototype.some) { Array.prototype.some = function(fun /*, thisp */) { "use strict"; if (this == null) throw new TypeError(); var t = Object(this), len = t.length >>> 0; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in t && fun.call(thisp, t[i], i, t)) return true; } return false; }; }
解决方案
>>>
is a right shift without sign extensionIf you use the
>>
operator on a negative number, the result will also be negative because the original sign bit is copied into all of the new bits. With>>>
a zero will be copied in instead.In this particular case it's just being used as a way to restrict the
length
field to an unsigned 31 bit integer, or in other words to "cast" Javascript's native IEEE754 "double" number into an integer.这篇关于什么是&QUOT;&GT;&GT;&GT;&QUOT;运营商JS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!