Underscore.js _.bitwiseXor() 方法
这 _。 bitwiseXor () 方法返回对所有参数使用按位异或 (^)运算符的结果。
句法:
_.bitwiseXor(val1, val2, ..., valn);
参数:此方法需要 n 个值对其进行操作。
返回值:此方法返回对所有参数使用按位 ^运算符的结果。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。 Underscore.js contrib 库可以使用npm install underscore-contrib –save 安装。
示例 1:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bX = _.bitwiseXor( 1, 3 );
console.log("The bitwiseXor is :", bX);
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bX = _.bitwiseXor( 1, 3, 5, 7 );
console.log("The bitwiseXor is :", bX);
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bX = _.bitwiseXor( 1 );
console.log("The bitwiseXor is :", bX);
输出:
The bitwiseXor is :
示例 2:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bX = _.bitwiseXor( 1, 3, 5, 7 );
console.log("The bitwiseXor is :", bX);
输出:
The bitwiseXor is : 0
示例 3:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-contrib');
var bX = _.bitwiseXor( 1 );
console.log("The bitwiseXor is :", bX);
输出:
The bitwiseXor is : 1