0.0.2 • Published 10 years ago

obx v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

Simple inheritance helper with named constructor.

Installation

$ npm install obx

Example

var Obj = require('obx');

// copy of object class
var Base = Obj.create();

// with named constructor "function Model() { Base.apply(this, arguments) }"
var BaseModel = Base.create('Model', {
    foo: 'bar',
    baz: 'foo'
}, {
    fn: function() { return 1 }
});

var Model = BaseModel.create(function Model() {
    BaseModel.apply(this, arguments); // super call
    // or this.__parent.apply(this, arguments);

    this.bar = 'baz';

    // self constructor
    console.log(this.__constructor.name) // >>> 'Model'
}, {
    foo: BaseModel.prototype.foo + '!',
    fn: function() {
        return this.__parent.prototype.fn() + 1;
    }

);

var model = new Model;

model.foo; // >>> 'foo!'
model.bar; // >>> 'baz'
model.baz; // >>> 'foo'
model.fn(); // >>> 2

Running tests

$ make test

Authors

License

MIT