Skip to content

Instantly share code, notes, and snippets.

@BevanR
Created January 25, 2017 23:04
Show Gist options
  • Save BevanR/7e461650aab1c7dac20aae6a18a058fd to your computer and use it in GitHub Desktop.
Save BevanR/7e461650aab1c7dac20aae6a18a058fd to your computer and use it in GitHub Desktop.
class Button {
click() {
// TODO Animate the button.
}
}
class RedButton {
button = new Button()
style = {
color: 'red',
}
click() {
this.button.click()
}
}
class ConfirmButton {
button = new Button()
style = {}
click() {
if (confirm('Are you sure?')) {
this.button.click()
}
}
}
class RedConfirmButton {
confirmButton = new ConfirmButton()
redButton = new RedButton()
click() {
// Use ConfirmButton's behaviour.
this.confirmButton.click()
}
get style() {
// But RedButton's style.
return this.redButton.style
}
}
type AnyButton = RedButton | Button | ConfirmButton | RedConfirmButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment