📅  最后修改于: 2022-03-11 15:01:30.797000             🧑  作者: Mango
this.go = function (currentState) {
if (currentState == LightState.GREEN) {
console.log("Green --> for 1 minute")
this.change(LightState.YELLOW)
return
}
if (currentState == LightState.YELLOW) {
console.log("Yellow --> for 10 seconds")
this.change(LightState.RED)
return
}
if (currentState == LightState.RED) {
console.log("Red --> for 1 minute");
this.change(LightState.GREEN)
return
}
if (currentState != LightState.GREEN && currentState != LightState.RED && currentState != LightState.YELLOW) {
throw Error("Invalid State")
}
}