| Example of Mixins To create mixins, simply declare lightweight classes that can be used as "behaviours". You can then apply these behaviours to a composition class: The applyMixins function is needed to do the work of composition. Syntax - class BeetleGuy implements Climbs, Bulletproof { }
- applyMixins (BeetleGuy, [Climbs, Bulletproof]);
Parameters | Parameter | Description | | derivedCtor | The class that you want to use as the composition class | | baseCtors | An array of classes to be added to the composition class | There are three rules to bear in mind with mixins: - You use the
implements keyword, not the extends keyword when you write your composition class - You need to have a matching signature to keep the compiler quiet (but it doesn’t need any real implementation – it will get that from the mixin).
- You need to call
applyMixins with the correct arguments.
|