Last active
March 28, 2017 07:58
Revisions
-
jacky810124 revised this gist
Jan 22, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,15 +18,15 @@ class Verifying extends State { } class VerifyFailed extends State { reject() { console.log('verifying') } } class VerifySucceed extends State { } -
jacky810124 revised this gist
Jan 22, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,8 @@ class State { class Verifying extends State { approve(data) { console.log('verify succeed', data) } reject() { console.log('verify failed') @@ -44,5 +44,5 @@ class Teacher { } const teacherA = new Teacher('Verifying') teacherA.approve({ name: 'jacky' }) -
jacky810124 created this gist
Jan 22, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ class State { approve() { throw 'Should override this function' } reject() { throw 'Should override this function' } } class Verifying extends State { approve() { console.log('verify succeed') } reject() { console.log('verify failed') } } class VerifyFailed extends State{ reject() { console.log('verifying') } } class VerifySucceed extends State{ } class Teacher { constructor(state) { const states = { Verifying, VerifySucceed, VerifyFailed } this.currentState = new states[state]() this.approve = this.currentState.approve this.reject = this.currentState.reject } } const teacherA = new Teacher('Verifying') teacherA.approve()