Lodash _.bitwiseRight() 方法
Lodash是一个基于 underscore.js 的 JavaScript 库。 Lodash 有助于处理数组、字符串、对象、数字等。
_.bitwiseRight() 方法用于返回对所有给定参数使用按位右运算符(>>) 的结果。
句法:
_.bitwiseRight( val1, val2,..., valn )
参数:此方法采用可变数量的参数并对它们进行按位右运算符。
返回值:此方法返回对所有参数使用按位右运算符(>>) 的结果。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Adding lodash-contrib library
var _ = require('lodash-contrib');
// Using the _.bitwiseRight() method
var bR = _.bitwiseRight( 1, 3 );
console.log("The bitwiseRight is :", bR);
Javascript
// Adding lodash-contrib library
var _ = require('lodash-contrib');
// Using the _.bitwiseRight() method
var bR = _.bitwiseRight( 5, 1 );
console.log("The bitwiseRight is :", bR);
Javascript
// Adding lodash-contrib library
var _ = require('lodash-contrib');
// Using the _.bitwiseRight() method
var bR = _.bitwiseRight( 1 );
console.log("The bitwiseRight is :", bR);
输出:
The bitwiseRight is : 0
示例 2:
Javascript
// Adding lodash-contrib library
var _ = require('lodash-contrib');
// Using the _.bitwiseRight() method
var bR = _.bitwiseRight( 5, 1 );
console.log("The bitwiseRight is :", bR);
输出:
The bitwiseRight is : 2
示例 3:
Javascript
// Adding lodash-contrib library
var _ = require('lodash-contrib');
// Using the _.bitwiseRight() method
var bR = _.bitwiseRight( 1 );
console.log("The bitwiseRight is :", bR);
输出:
The bitwiseRight is : 1