Last active
March 1, 2020 12:38
-
-
Save itsmunim/496728b50b7bbba68a5e0e4244604a18 to your computer and use it in GitHub Desktop.
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 characters
| class SwimMixin { | |
| // prevents duplication of implementation; | |
| // can be a helper/util class as well | |
| swim(context) { | |
| // swim implementation | |
| } | |
| } | |
| class Animal { | |
| walk() { | |
| this.throwNotImplemented(); | |
| } | |
| fly() { | |
| this.throwNotImplemented(); | |
| } | |
| swim() { | |
| this.throwNotImplemented(); | |
| } | |
| throwNotImplemented() { | |
| throw new Error('Not implemented'); | |
| } | |
| } | |
| class Fish extends Animal { | |
| swim() { | |
| swimMixinInstance.swim(this); | |
| } | |
| } | |
| const fish = new Fish(); | |
| fish.swim(); // the fish swims | |
| fish.fly(); // sorry not implemented in this kind of object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment