Simple inheritance boilerplate for Javascript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Constructr Build Status

Simple inheritance boilerplate for Javascript with zero dependencies and some spice on top.

Note: Readme will be updated soon with much better explanation and examples. See TODO section at bottom.

Installation & Usage

npm install constructr

For now you can just use browserify for the browser (will be sorting UMD packaging v. soon)

Quick and dirty example

var BaseClass = Constructr.extend({
	day: 'Monday',
	initialize: function(day) { = day ||;
	hello: function(text) {
		return 'Hello '+text+'. It\'s ''!';

var ClassA = BaseClass.extend();
var ClassB = BaseClass.extend({
	hello: function(text) {
		var super = this.__super__.hello.apply(this, arguments); // Call super
		return super+' Isn\'t it a nice day?';

var myClassA = new ClassA();
console.log(myClassA.hello('world')); // Hello world. It's Monday!

var myClassB = new ClassB('Friday');
console.log(myClassB.hello('Chris')); // Hello Chris. It's Friday!

And of course you don't have to pass one big object to extend the prototype with all your methods.

var BaseClass = Constructr.extend({
	day: 'Monday'

BaseClass.prototype.initialize = function(day) { = day ||;

BaseClass.prototype.hello = function(text) {
	return 'Hello '+text+'. It\'s ''!';

Want to reuse common collections of methods? Ie. Horizontal inheritance?

var commonMethods = {
	goodbye: function() { return 'Cya!'; },
	brb: function() { return '1 Sec.'; }

var ClassA = SomeParent.extend().mixes(commonMethods);
var ClassB = SomeOtherBranchInClassHierarchy.extend().mixes(commonMethods);

var myClassA = new ClassA();
var myClassB = new ClassB();

console.log(myClassA.goodbye()); // Cya!
console.log(myClassB.goodbye()); // Cya!

Define object properties on the prototype?

var Person = Constructr.extend();

Person.def('name', {
	get: function() { return this.get('name'); },
	set: function(value) { return this.set('name', value); },

var rob = new Person(); = "Robert";
console.log(; // Robert


  • Documentation
  • Better introduction, explanation and examples.
  • Example how it can be used in existing libraries (Eg. Backbone)