Javascript函数返回:<&书信电报;及|
当我看到这个函数时,我正在查看google“书签气泡库”的源代码Javascript函数返回:<&书信电报;及|,javascript,Javascript,当我看到这个函数时,我正在查看google“书签气泡库”的源代码 /** * 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 {*=}
/**
* 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);
};
/**
*从0和127(含)之间的4个整数片段创建版本号。
*@param{*=}opt_a是主要版本。
*@param{*=}opt_b是次要版本。
*@param{*=}opt_c为修订号。
*@param{*=}选择内部版本号。
*@return{number}版本的表示形式。
*@私人
*/
google.bookmarkbubble.Bubble.prototype.getVersion=函数(opt_a、opt_b、opt_c、opt_d){
//我们希望允许任何类型到数字的隐式转换,同时避免
//有关类型的编译器警告。
return/**@type{number}*/(opt_a)下面是一些简单的JavaScript,可以查看发生了什么(使用.toString(2)返回数字的二进制表示):
console.log((8).toString(2));
> 1000
console.log((8>>1.toString(2));
>0100(右移一个空格)
console.log((8 1101)(组合如下3个数字:
1000
1001
0101
====
1101如果任何数字为1,则在该数字中返回1)
请看这里的链接@elclanrs谢谢,elclanrs和Joseph。请回答我的帖子,这样我就可以接受答案了
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)