什么是">>>"运营商JS? [英] What is ">>>" operator in JS?

查看:292
本文介绍了什么是">>>"运营商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 than

Found 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 extension

If 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆