js 权限二进制

const READ = 0b1;
const CREATE = 0b10;
const UPDATE = 0b100;
const DELETE = 0b1000;

const rights = READ | UPDATE | DELETE //组合权限读 更新 删除 13
console.log(rights) //13
if ((rights && READ) === 1) {
  console.log('有read权限')
} else {
  console.log('没有read权限')
}
if ((rights ^ READ) === 0b1100) {
  console.log('删除read权限')
} else {
  console.log('有read权限')
}

 

posted @ 2024-08-02 17:17  howhy  阅读(6)  评论(0编辑  收藏  举报