Simple FSM in Javascript (based on https://github.com/joelhooks/robotlegs-utilities-StateMachine with added fixes)