let unit = new Unit(); console.log('add UnitStatus.US_1 UnitStatus.US_2'); unit.setFlag(UnitStatus.US_1 | UnitStatus.US_2); console.log('unit has UnitStatus.US_1?', unit.hasFlag(UnitStatus.US_1)); console.log('unit has UnitStatus.US_2?', unit.hasFlag(UnitStatus.US_2)); console.log('unit has UnitStatus.US_3?', unit.hasFlag(UnitStatus.US_3)); console.log('unit has UnitStatus.US_4?', unit.hasFlag(UnitStatus.US_4)); console.log('remove UnitStatus.US_1'); unit.clearFlag(UnitStatus.US_1); console.log('unit has UnitStatus.US_1?', unit.hasFlag(UnitStatus.US_1)); console.log('unit has UnitStatus.US_2?', unit.hasFlag(UnitStatus.US_2)); console.log('unit has UnitStatus.US_3?', unit.hasFlag(UnitStatus.US_3)); console.log('unit has UnitStatus.US_4?', unit.hasFlag(UnitStatus.US_4)); console.log('reset unit status'); unit.resetFlag(); console.log('unit has UnitStatus.US_1?', unit.hasFlag(UnitStatus.US_1)); console.log('unit has UnitStatus.US_2?', unit.hasFlag(UnitStatus.US_2)); console.log('unit has UnitStatus.US_3?', unit.hasFlag(UnitStatus.US_3)); console.log('unit has UnitStatus.US_4?', unit.hasFlag(UnitStatus.US_4));
输出结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
add UnitStatus.US_1 UnitStatus.US_2 unit has UnitStatus.US_1? true unit has UnitStatus.US_2? true unit has UnitStatus.US_3? false unit has UnitStatus.US_4? false remove UnitStatus.US_1 unit has UnitStatus.US_1? false unit has UnitStatus.US_2? true unit has UnitStatus.US_3? false unit has UnitStatus.US_4? false reset unit status unit has UnitStatus.US_1? false unit has UnitStatus.US_2? false unit has UnitStatus.US_3? false unit has UnitStatus.US_4? false