首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 ><<函数返回:

<<函数返回:
EN

Stack Overflow用户
提问于 2014-02-04 07:20:45
回答 1查看 55关注 0票数 0

当我看到这个函数时,我正在google的"Bookmark泡库“源代码中查找

代码语言:javascript
复制
/**
* Creates a version number from 4 integer pieces between 0 and 127 (inclusive).
* @param {*=} opt_a The major version.
* @param {*=} opt_b The minor version.
* @param {*=} opt_c The revision number.
* @param {*=} opt_d The build number.
* @return {number} A representation of the version.
* @private
*/
google.bookmarkbubble.Bubble.prototype.getVersion_ = function(opt_a, opt_b,opt_c, opt_d) {
// We want to allow implicit conversion of any type to number while avoiding
// compiler warnings about the type.
return /** @type {number} */ (opt_a) << 21 |
  /** @type {number} */ (opt_b) << 14 |
  /** @type {number} */ (opt_c) << 7 |
  /** @type {number} */ (opt_d);
};

我不明白双标号“<<”和“单字母”

如果有人理解,他能不能增加我的javascript知识,并告诉我这个“返回”是如何工作的?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-04 07:33:29

下面是一些简单的JavaScript来查看发生了什么(使用.toString(2)返回数字的二进制表示):

代码语言:javascript
复制
console.log((8).toString(2));
> 1000
console.log((8>>1).toString(2));
> 0100 (shift right one space)
console.log((8<<1).toString(2));
> 10000 (shift left one space)
console.log((8|9|5).toString(2));
> 1101 (combines the 3 numbers like this:

  1000
  1001
  0101
  ====
  1101 if any digit is 1 then return a 1 in that digit)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21546298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档