1.0.0 • Published 9 years ago

sextend v1.0.0

Weekly downloads
3
License
WTFPL
Repository
github
Last release
9 years ago

sextend

sextend ("super extend") allows you to to do inheritance in JavaScript and in much the same manner as util.inherits in Node.js, except now you also inherit class variables too! Isn't that cool?

For further awesome, you can also add mixins at the same time!

Usage

For extending, just use it like you would use util.inherits in node.js.

In node:

var sextend = require('sextend');

function A(){}
A.coolStaticVar = "fun";
function B(){}
sextend(B, A);

console.log(A.coolStaticVar); // fun

In browser:

<script src="sextend.js"></script>
<script>
function A(){}
A.coolStaticVar = "fun";
function B(){}
sextend(B, A);

console.log(A.coolStaticVar); // fun
</script>

For mixins, you can add extra arguments that are mixin functions. A mixin function is just a function that refers to the destination object as this and adds properties accordingly.

Example:

function A(){}
function MyMixin(){
  this.prototype.instanceVar = 1;
  this.staticVar = 2;
}
sextend(A, null, MyMixin); // superclass is optional

console.log(A.staticVar); // 2
console.log((new A()).instanceVar); // 1

License

WTFPL

1.0.0

9 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

11 years ago