Problem
Uncaught TypeError: state.removeFlag is not a function
Extra Information
I'm having trouble with the code below, giving me the error above. My intention is simple, I want to set up two functions in a 'class' then call them, but I am getting the above error and I can't spot the problem. I was hoping that another pair of eyes might help. I appreciate any help you can give me.
Note: Flags.CROSS_SLOT has a value of 1
Code
function State(){
this.state = 0; //bitstring representing the user's choices in the UI
this.addFlag = function(flag){
state = (state | flag);
}
this.removeFlag = function(flag){
state = (~state | flag);
}
}
var state = new State();
state.addFlag(Flags.CROSS_SLOT);
console.log(state.state);
state.removeFlag(Flags.CROSS_SLOT);
console.log(state.state);