extasy

Extend function inspired by YUI, coffeescript, typescript and google closure inheritance patterns.

extasy

Extend function inspired by coffeescript, typescript and google closure inheritance patterns.

npm install extasy

Yuidocs documentation here

  • link only works when checkout repo and preview README locally
var extend = require('./lib/main.js');
 
function Parent() {};
Parent.prototype.foo = function(x, y) {
    return x + y;
};
 
function Child() {};
// must extend before overwriting prototype methods!
extend(Child, Parent);
Child.prototype.foo = function(x, y) {
    return 2 + this.super_.foo(x, y);
};
 
/*--------------------------------------
no tests throw an error
---------------------------------------*/
var ChildInst = new Child();
 
var assert = require('assert');
assert(ChildInst.constructor === Child);
assert(ChildInst.super_ === Parent.prototype);
assert(Object.getPrototypeOf(ChildInst) === Child.prototype);
assert(Object.getPrototypeOf(Object.getPrototypeOf(ChildInst)) === Parent.prototype);
assert(ChildInst instanceof Child);
assert(ChildInst instanceof Parent);
 
console.log('ok');