extasy
v0.1.1
Published
Extend function inspired by YUI, coffeescript, typescript and google closure inheritance patterns.
Downloads
15
Readme
extasy
Extend function inspired by coffeescript, typescript and google closure inheritance patterns.
Install
npm install extasy
Docs
- link only works when checkout repo and preview README locally
Full Example
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');