State Pattern Example in JS