美文网首页
各种写法

各种写法

作者: 韩梅梅梅梅 | 来源:发表于2019-05-07 16:04 被阅读0次

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

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; })

相关文章

网友评论

      本文标题:各种写法

      本文链接:https://www.haomeiwen.com/subject/natyoqtx.html