Backbone like Class.extend utility for Node

npm install class-extend
1 812 downloads in the last day
11 699 downloads in the last week
47 769 downloads in the last month

Class.extend Build Status

Backbone's .extend like inheritance helper for Node.js


var Base = require('base');

// Extend from the blank class
var Sub = Base.extend();

// Add the .extend helper to a class
MyClass.extend = Base.extend;


.extend allow you to assign prototype and static methods.

If no constructor method is assigned, the parent constructor method will be called by default.

// Extend a class
var Sub = Parent.extend({
  // Overwrite the default constructor
  constructor: function () {},

  // Sub class prototypes methods
  hello: function () { console.log('hello'); }
}, {
  // Constructor static methods
  hey: function () { console.log('hey'); }

// LOG: hey

var instance = new Sub();
// LOG: hello


Sub classes are assigned a __super__ static property pointing to their parent prototype.

var Sub = Parent.extend();
assert(Sub.__super__ === Parent.prototype);


Copyright (c) 2013 Simon Boudrias
Licensed under the MIT license.

npm loves you