Skip to content
A Simple Javascript Inheritance implementation
JavaScript HTML
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
README.md
bower.json
classy.js
classy.min.js
index.html
test.js

README.md

Classy

Classy is a Javascript Inheritance implementation. This is pretty much everything you need to know.

You will gain access to a simple way to implement a Javascript Class in your code along with a useful "include" method.


Example

Building.js

Class( "Building", {

    //constructor
    Building: function( type ) {

        this.type = type;
        this.floors = 1;
        this.collapsed = false;

    },

    //methods
    addFloors: function( number ) {

        this.floors += number;

    },

    demolish: function() {
        this.collapsed = true;
    }

});

Home.js

Class( "Home", {

    //constructor
    Home: function( type, familyName ) {

        Building.call( this, type );
        this.familyName = familyName;

    },

    //methods
    changeName: function( name ) {

        this.familyName = name;

    },

    demolish: function() {
        //calling super "demolish" method
        this._demolish();
        alert("Adieu!");
    }

})._extends( "Building" );

Constructor name must be the same of the Class one. Class extension is achieved through the function _extends ( "className" ). You can see the file "index.html" to see how to work with the include method. Include has a useful feature which allows you to import multiple files at once ( you can specify an array of strings or a single string, and you're free to avoid to insert the ".js" file extension ):

var toInclude = [ "js/FirstClass.js", "js/SecondClass" ];
//var toInclude  = "js/OtherClass.js";

include( toInclude, function() {

        var first_instance = new FirstClass( params );

});

That's all you need to know to get started. And remember, always stay classy.

Something went wrong with that request. Please try again.