January 2020
Intermediate to advanced
548 pages
13h 36m
English
Conventionally, an extension is used not only to create semantic sub-classes but also to provide mixins of methods. JavaScript provides no native mixing-in mechanism so to achieve it you, either need to augment the prototype after the definition or effectively inherit from your mixins (as if they are superclasses).
Augmenting a prototype with your mixins is the simplest approach. We can achieve this by specifying mixins as objects and then adding them to prototype of a class via a convenient method such as Object.assign:
const fooMixin = { foo() {} };const bazMixin = { baz() {} };class MyClass {}Object.assign(MyClass.prototype, fooMixin, bazMixin);
This approach, however, does not allow MyClass to override its own mixin ...
Read now
Unlock full access