const Player = function() {
let currentState = {},
states = {
run: function() {
console.log('run')
},
jump: function() {
console.log('jump')
},
shoot: function() {
console.log('shoot')
},
}
const Actions = {
changeState: function() {
let args = [...arguments]
currentState = {}
if(args.length) {
args.forEach(v => {
currentState[v] = true
})
}
return this
},
dos: function() {
if(Object.keys(currentState).length === 0) return
for(let i in currentState) {
states[i] && states[i]()
}
}
}
return {
change: Actions.changeState,
dos: Actions.dos
}
}()
console.log(Player)
Player.change('jump','run').dos()
console