The validator will check if transition from current state is allowed or not.
Script function validator() { var current_state = this.get_state(); var new_state = this.next_state(); if (this.transition_allowed(current_state, new_state)) { this.set_state(new_state); } }