Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jondubois/nmix
A simple JavaScript mixin function which facilitates multiple inheritance.
https://github.com/jondubois/nmix
Last synced: 12 days ago
JSON representation
A simple JavaScript mixin function which facilitates multiple inheritance.
- Host: GitHub
- URL: https://github.com/jondubois/nmix
- Owner: jondubois
- Created: 2012-12-03T14:40:39.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-12-08T01:31:30.000Z (about 12 years ago)
- Last Synced: 2024-11-07T15:09:30.169Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 125 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
nmix
====A simple mixin module which facilitates multiple inheritance in JavaScript.
## Installation
```bash
npm install nmix
```## Example Usage
```js
var nmix = require('nmix');var Apple = function(adjective) {
this.info = function() {
return 'a ' + adjective + ' apple';
}
this.crunch = function() {
return 'CRUNCH CRUNCH CRUNCH!';
}
}var Banana = function() {
this.info = function(size) {
return 'a ' + size + ' banana';
}
this.splat = function() {
return 'SPLAT!';
}
}var FruitSalad = nmix(function(appleColor) {
this.initMixin(Apple, appleColor);
this.initMixin(Banana);
this.info = function() {
var appleInfo = this.callMixinMethod(Apple, 'info');
var bananaInfo = this.callMixinMethod(Banana, 'info', 'big');
var str = 'A fruit salad containing ' + appleInfo + ' and ' + bananaInfo;
return str;
}
});var ImprovedFruitSalad = nmix(function() {
this.initMixin(FruitSalad, 'red');
this.info = function() {
var str = this.callMixinMethod(FruitSalad, 'info') + ' - An improved version';
return str;
}
});var fruitSalad = new FruitSalad('green');
console.log(fruitSalad.splat()); // outputs 'SPLAT!'
console.log(fruitSalad.crunch()); // 'CRUNCH CRUNCH CRUNCH!'
console.log(fruitSalad.info()); // 'A fruit salad containing a green apple and a big banana'console.log();
var improvedFruitSalad = new ImprovedFruitSalad();
console.log(improvedFruitSalad.info()); // 'A fruit salad containing a red apple and a big banana - An improved version'
```