An expressive, cross platform JavaScript Class provider with a classical interface to prototypal inheritance.
varPerson=klass(function(name){this.name=name}).statics({head: ':)',feet: '_|_'}).methods({walk: function(){}})varSuperHuman=Person.extend(function(name){// super class is automagically called}).methods({walk: function(){this.supr()this.fly()},fly: function(){}})newSuperHuman('Zelda').walk()varFoo=klass({foo: 0,initialize: function(){this.foo=1},getFoo: function(){returnthis.foo},setFoo: function(x){this.foo=xreturnthis.getFoo()}})note: initialize will be called on class invocation
because sometimes you want to overwrite OR mixin an instance method
// note you can optionally pass an object literal to extend too ;)varAlien=SuperHuman.extend({beam: function(){this.supr()// beam into space}})varSpazoid=newAlien('Zoopo')if(beamIsDown){Spazoid.implement({beam: function(){this.supr()// fallback to jetsthis.jets()}})}Klass is Common JS compliant and provides the Modules 1.1 interface to allow two flavors of development. See the implementations below:
<scriptsrc="path/to/klass.js"></script><!-- klass() is exposed to context -->npm install klassvarklass=require('klass')add klass to your ender compilation
ender add klassnpm install make make testKeep your edits localized to src/klass.js
MIT