class Action { handle() { handle1(); handle2(); handle3(); } handle1() { console.log('1'); } handle2() { console.log('2'); } handle3() { console.log('3'); } }
// 請假審批,須要組長審批,經理審批,最後總監審批 class Action { constructor(name) { this.name = name; this.nextAction = null; } setNextAction(action) { this.nextAction = action; } handle() { console.log(`${this.name} 審批`); if (this.nextAction != null) { this.nextAction.handle(); } } } // 測試 let a1 = new Action('組長'); let a2 = new Action('經理'); let a3 = new Action('總監'); a1.setNextAction(a2); a2.setNextAction(a3); a1.handle();