klass

Class provider with classical inheritance interface

An expressive, cross platform JavaScript Class provider with a classical interface to prototypal inheritance.

var Person = klass(function (name) {
  this.name = name
})
  .statics({
    head: ':)',
    feet: '_|_'
  })
  .methods({
    walkfunction () {}
  })
var SuperHuman = Person.extend(function (name) {
  // super class is automagically called 
})
  .methods({
    walkfunction() {
      this.supr()
      this.fly()
    },
 
    flyfunction() {}
 
  })
 
new SuperHuman('Zelda').walk()
var Foo = klass({
  foo: 0,
  initializefunction() {
    this.foo = 1
  },
  getFoofunction () {
    return this.foo
  },
  setFoofunction (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

// note you can optionally pass an object literal to extend too ;) 
var Alien = SuperHuman.extend({
  beamfunction() {
    this.supr()
    // beam into space 
  }
})
 
var Spazoid = new Alien('Zoopo')
 
if (beamIsDown) {
  Spazoid.implement({
    beamfunction() {
      this.supr()
      // fallback to jets 
      this.jets()
    }
  })
}

Klass is Common JS compliant and provides the Modules 1.1 interface to allow two flavors of development. See the implementations below:

<script src="path/to/klass.js"></script>
<!-- klass() is exposed to context -->
npm install klass
var klass = require('klass')

add klass to your ender compilation

ender add klass
npm install
make
make test

Keep your edits localized to src/klass.js

MIT