可组合散列数值判断权限

const CREATE=ob0001;
const DELETE=ob0010;
const UPDATE=ob0100;
const DETAIL=ob1000;

const result=CREATE | DELETE
//result结果为ob0011
(result & DELETE)===DELETE

(result & DELETE)的结果为0010

&与运算:2个都是1才是0
|或运算:任意一个为1就是1

另外如果需要剔除某个权限,只需2个二进制相减即可

你可能感兴趣的:(前端,javascript,开发语言)