node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



classdef provides some incredibly bare-bones syntactic sugar for declaring classes in Javascript.

It wires up the prototype chain (inheritance) and copies things into the prototype object (your class's definition) and that's it. It does not add its own properties or methods to your objects. It does not create a super method or property. It has essentially zero features. It's wonderful.


var MyClass = classdef([superclass,] [mixins, ...] classDefinition);

classDefinition should be an object containing all of the functions you want the class to have. If one of those functions is named constructor, it will be used as the class's constructor.

You may optionally pass a superclass to inherit from, plus any number of mixins.

  • The superclass may be null.
  • You must manually call the superclass's constructor if you want that to happen (e.g.;
  • Mixins should be objects. All of their properties will be copied onto the class's prototype, in order. Mixins are usually employed to add additional functions to a class.


// Basic usage 
var MyClass = classdef({
  constructor: function() {
    // ... 
  someFunc: function() {
    // ... 
// Here 'Fruit' is the superclass, and 'Edible' and 'Squeezable' are mixins. 
var Orange = classdef(Fruit, Edible, Squeezable, {
  constructor: function() {;
    // ... 
  peel: function() {
    // ... 
// No superclass but mixins 
var Foo = classdef(null, Barable, Bazable, {
  constructor: function() {}


Copyright (c) 2012 Ned Burns Licensed under the MIT license.