Simple Javascript Inheritance by John Resig

npm install clah
7 downloads in the last week
38 downloads in the last month


Simple JavaScript Inheritance with bound callbacks

All credit for the inheritance system goes to John Resig. I adapted it to work both with Node.js or in a browser, and added a function to generate bound callbacks.

// define a class
var Person = Class.extend({

  // this is the constructor
  init : function(name) { = name;

  // you can use instance properties in your methods
  hello : function() {
    console.log("Hello, I'm " + + "!");

// define a subclass
var Pirate = Person.extend({

  // you can override methods
  hello : function() {
    console.log("Ahoy! Me be " + + ".");

new Person('Jim').hello();    // #=> "Hello, I'm Jim!"
new Pirate('John').hello();   // #=> "Ahoy! Me be John."

// create a bound callback
var jane = new Person('Jane');
var callback = jane.callback('hello');

// you can use this callback anywhere, it will always be bound to the instance
callback();   // #=> "Hello, I'm Jane!"

Clah is tested with Jasmine and Travis CI.

  • master Build Status
  • develop Build Status


With NPM:

npm install clah

In a browser:

<script type='text/javascript' src='/path/to/your/assets/clah.min.js'></script>

Download: Production (minified), Development (uncompressed).

Original Blog Post

npm loves you