# klass

> Class provider with classical inheritance interface

Latest version **1.4.1** (published 2015-07-16) · 0 weekly downloads

## Install

```sh
npm install klass
pnpm add klass
yarn add klass
bun add klass
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2015-07-16 |
| First published | 2011-03-10 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.4.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 749 |
| Author | Dustin Diaz |
| Maintainers | polvero, ded, fat |
| Keywords | ender, class, prototype, inheritance, oop |

## Links

- npm: https://www.npmjs.com/package/klass
- Repository: https://github.com/ded/klass
- Issues: https://github.com/ded/klass/issues
- npm.io page: https://npm.io/package/klass

## Recent versions

- 1.4.1 (latest) — 2015-07-16
- 1.4.0 — 2014-02-12
- 1.3.1 — 2014-02-11
- 1.3.0 — 2013-04-30
- 1.2.3 — 2012-11-14
- 1.2.2 — 2012-01-13
- 1.2.1 — 2011-09-28
- 1.2.0 — 2011-09-13
- 1.1.0 — 2011-09-12
- 1.0.6 — 2011-06-26
- 1.0.5 — 2011-06-10
- 1.0.4 — 2011-05-17
- 1.0.3 — 2011-04-21
- 1.0.2 — 2011-04-10
- 1.0.1 — 2011-04-09
- … 10 more at https://npm.io/package/klass/versions

## README

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

## API
### creating a Class

``` js
var Person = klass(function (name) {
  this.name = name
})
  .statics({
    head: ':)',
    feet: '_|_'
  })
  .methods({
    walk: function () {}
  })
```

### Subclassing

``` 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()
```

### Object Literal Interface

``` 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*

### Implement

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()
    }
  })
}
```

## Environments
Klass is [Common JS](http://commonjs.org) compliant and provides the [Modules 1.1](http://wiki.commonjs.org/wiki/Modules/1.1) interface to allow two flavors of development. See the implementations below:

### Browser

``` html
<script src="path/to/klass.js"></script>
<!-- klass() is exposed to context -->
```

### As a node module

``` sh
npm install klass
```

``` js
var klass = require('klass')
```

### Ender compatibility
add `klass` to your [ender](http://enderjs.com) compilation

``` sh
ender add klass
```

### Developers

``` sh
npm install
make
make test
```

Keep your edits localized to `src/klass.js`

## LICENSE
    MIT

### Happy Klassing!

---
_Source: https://npm.io/package/klass · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
