当我看到这个函数时,我正在google的"Bookmark泡库“源代码中查找
/**
* 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知识,并告诉我这个“返回”是如何工作的?
谢谢
发布于 2014-02-04 07:33:29
下面是一些简单的JavaScript来查看发生了什么(使用.toString(2)返回数字的二进制表示):
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)https://stackoverflow.com/questions/21546298
复制相似问题