2.3.1 • Published 12 years ago
classical v2.3.1
Classical
A simple cross-platform functional provider of classical inheritance for Javascript.
Documentation
Creating a Class
var Mammal = require('classical').create(function() {
this.name = null;
this.constructor = function(name) {
this.name = name;
};
this.speak = function(text) {
console.log('%s says, "%s"', this.name, text);
};
});
Extension
var Dog = Mammal.extend(function() {
this.breed = null;
this.constructor = function(name, breed) {
this.breed = breed;
};
this.speak = function() {
this.super.speak('Woof!');
}
});
Instantiation
var Spot = new Dog('Spot', 'Dalmation');
Spot.speak(); // Outputs: 'Spot says, "Woof!"' to the console.
Interfaces
var Animal = require('classical').interface(function() {
this.speak = function() {};
});
Mammal.implements(Animal);