Xmix
Xmix is a pack of mixin related utility methods, which will let you create, and apply custom mixins, by injecting them into the prototype chain.
Example
; const Mixin = mixin; { thisparentProperty = 'comes first'; } MixinParent { super; thischildProperty = 'comes last' } const child = ; ;
API
mixin(Function, [...Function]) function
description: Takes a single mixin (or more) and returns a function which applies the mixins in series once invoked. This function can extend an additional extra class by simply invoking it with the desired class, or we can either skip that stage and call the .class
property.
returns: extend(Function) function
usage:
A BParent
or without providing an additional class:
A Bclass
mixin.new(Function, [Function]) function
description: Takes a factory function which should return a child class of the provided parent class. An additional transformation function may be provided as the second argument for syntactic sugar.
returns: mixin(Function) function
usage:
const Mixin = mixin;
Then, the mixin can either be applied using the following methods:
MixinParent {}// orParent {}// or in case we're not interested in Parent classclass {}
An additional transformation function may be provided as well:
const Mixin = mixin;
mixin.of(Object, Function) function
description: Checks if a given instance is affected by a given mixin.
returns: Boolean
usage
mixin;
Download
The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm
):
npm install xmix
License
MIT