Class provider with classical inheritance interface
npm install klass`` js`
var Person = klass(function (name) {
this.name = name
})
.statics({
head: ':)',
feet: '_|_'
})
.methods({
walk: function () {}
})
` js
var SuperHuman = Person.extend(function (name) {
// super class is automagically called
})
.methods({
walk: function() {
this.supr()
this.fly()
},
fly: function() {}
})
new SuperHuman('Zelda').walk()
`
` js`
var Foo = klass({
foo: 0,
initialize: function() {
this.foo = 1
},
getFoo: function () {
return this.foo
},
setFoo: function (x) {
this.foo = x
return this.getFoo()
}
})
note: initialize will be called on class invocation
because sometimes you want to overwrite OR mixin an instance method
` js
// note you can optionally pass an object literal to extend too ;)
var Alien = SuperHuman.extend({
beam: function() {
this.supr()
// beam into space
}
})
var Spazoid = new Alien('Zoopo')
if (beamIsDown) {
Spazoid.implement({
beam: function() {
this.supr()
// fallback to jets
this.jets()
}
})
}
`
` html`
` sh`
npm install klass
` js`
var klass = require('klass')
to your ender compilation` sh
ender add klass
`$3
` sh
npm install
make
make test
`Keep your edits localized to
src/klass.js`