取余运算在模式选择中的运用
var mode = { 0: 'sequence', 1: 'loop', 2: 'random' } var m = 1 function changeMode() { var newMode = (m + 1) % 3 console.log(mode[newMode]) m++ } changeMode() // random changeMode() // sequence changeMode() // loop changeMode() // random