Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fetchte/defclass
Simple Classical Inheritance
https://github.com/fetchte/defclass
Last synced: about 1 month ago
JSON representation
Simple Classical Inheritance
- Host: GitHub
- URL: https://github.com/fetchte/defclass
- Owner: fetchTe
- License: mit
- Created: 2015-11-30T04:07:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-16T05:00:53.000Z (almost 8 years ago)
- Last Synced: 2024-11-07T04:11:37.606Z (about 2 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# defclass
Simple classical inheritance that is a whopping ten lines. Its [Augment](http://github.com/javascript/augment) without the augment.In the words of Aadit Shah
> No premature optimization. No need to read the documentation of libraries like ClassManager. I can directly focus on the task at hand and optimize those things that really need optimization.## Usage
```js
const defclass = require('defclass');const Beer = defclass({
constructor: function (type) {
this.type = type;
this.count = 100;
this.temp = 'cold';
},
getADrink: function () {
--this.count;
console.log(`Here's a ${this.temp} ${this.type}!`);
}
});const favBeer = new Beer('Spotted Cow');
favBeer.getADrink(); // Here's a cold Spotted Cow!
```If you need to inherit from another class use `extend`.
```js
const GrabAnother = defclass.extend(Beer, {
sing: function () {
console.log(`${this.count} bottles of ${this.temp} ${this.type}'s on the wall.`);
}
});const makeMeDance = new GrabAnother(`John's White Ale`);
makeMeDance.getADrink(); // Here's a John's White Ale!
makeMeDance.sing(); // 99 bottles of cold John's White Ale's on the wall.
```## Credit
+ [Aadit M Shah](http://aaditmshah.github.io/)