proclass

Classical inheritance with protected members.

npm install proclass
18 downloads in the last week
18 downloads in the last month

Build Status NPM version

Basic classical inheritance with protected members and accessible overwritten methods.

Usage

Include Proclass in your application using strict mode (available on npm) and let the inheritance begin!

Example

"use strict";

var Proclass = require("proclass");

var Foo = Proclass.extend({

    _init: function(baz){
        // Constructor function for class
        // Only available as constructor or within constructor of Class objects
        // that inherit from this (via `this._parent()`)
    },

    somePublicFunction: function() {
        // Available to this class, Class objects that inherit from this,
        // and anywhere outside of this class
    },

    _someProtectedFunction: function() {
        // Only available to this class and Class objects that inherit from this
    }

});

var Bar = Foo.extend({

    somePublicFunction: function() {
        // Will overwrite `Foo.somePublicFunction()`
        // `Foo.somePublicFunction()` still accessible via `this._parent()`
    }

});

var bar = new Bar(baz);

Thanks

John Resig's Simple JavaScript Inheritance was a huge inspiration to this project. After trying several different approaches, I kept coming back to using a method very similar to his. (And I learned quite a bit because of it.) So, thanks!

Also, prodecjs gave me hope that protected members were indeed possible in JavaScript, and helped me with the basic implementation. Thanks!

npm loves you