各种写法

根据不同状态进行事件处理

init() {
            this.stateHandler = {
                [State.Standby]: this.sH_standby,
                [State.Moving]: this.sH_moving,
                [State.CheckAttacking]: this.sH_checkAttack,
                [State.Callback]: this.sH_callback,
            };
        }

调用时根据状态值取到对应方法

let handler = this.stateHandler[curState];

遍历全部成员

function forEach(handler: { (ship: GShip, ...args) }, ...args) {
            handler(this.flagship, ...args);
            const ships = this.ships;
            for (let guid in ships) {
                handler(ships[guid].ship, ...args);
            }
        }

 this.forEach(function (ship: GShip, team: Team, interShips?: GShip[]) {
                    \\\............
                }, this, interShips);

 this.forEach(ship => {ship.vo.inBattle = false; })

你可能感兴趣的:(各种写法)