Last active
March 28, 2017 07:58
-
-
Save jacky810124/729dfc6413fa8a5bef4465c3f69be78d to your computer and use it in GitHub Desktop.
This file contains 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 characters
class State { | |
approve() { | |
throw 'Should override this function' | |
} | |
reject() { | |
throw 'Should override this function' | |
} | |
} | |
class Verifying extends State { | |
approve(data) { | |
console.log('verify succeed', data) | |
} | |
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({ name: 'jacky' }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment