const allowA = 1 << 0
const allowB = 1 << 1
const allowC = 1 << 2
const allowD = 1 << 3

let flag;

setPer(allowD)
addPer(allowC)
console.log(isAllow(allowC))
console.log(isAllow(allowA))

console.log(flag)

function setPer(per) {
  flag = per;
}

function addPer(per) {
  flag = flag | per;
}

function deletePer(per) {
  flag = flag&~per;
}

function isAllow(per) {
  return (flag&per) === per;
}

function isNotAllow(per) {
  return (flag&per) === 0
}
Copy the code