class-extend

Backbone like Class.extend utility for Node

Class.extend

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 
  constructorfunction () {},
 
  // Sub class prototypes methods 
  hellofunction () { console.log('hello'); }
}, {
  // Constructor static methods 
  heyfunction () { console.log('hey'); }
});
 
Sub.hey();
// LOG: hey 
 
var instance = new Sub();
instance.hello();
// 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.