classical

Functional Classical Inheritance for Javascript

Classical

A simple cross-platform functional provider of classical inheritance for Javascript.

Documentation

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);
    };
});
var Dog = Mammal.extend(function() {
    this.breed                          = null;
 
    this.constructor = function(namebreed) {
        this.breed                      = breed;
    };
 
    this.speak = function() {
        this.super.speak('Woof!');
    }
});
var Spot = new Dog('Spot', 'Dalmation');
Spot.speak(); // Outputs: 'Spot says, "Woof!"' to the console. 
var Animal = require('classical').interface(function() {
    this.speak                          = function() {};
});
Mammal.implements(Animal);