# coffee_classkit

> Utilities for coffee-script classes

Latest version **0.5.0** (published 2013-10-21) · BSD license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2013-10-21 |
| First published | 2013-04-28 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Max Melentiev |
| Maintainers | printercu |
| Keywords | coffee-script, class, classes, inheritance |

## Links

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

## Recent versions

- 0.5.0 (latest) — 2013-10-21
- 0.4.2 — 2013-09-03
- 0.4.1 — 2013-08-18
- 0.4.0 — 2013-08-14
- 0.3.0 — 2013-08-01
- 0.2.0 — 2013-07-13
- 0.0.1 — 2013-04-28

## README

# CoffeeClasskit

You can make much more with CoffeeScript classes.

```
npm install coffee_classkit
```

```coffee
classkit = require 'coffee_classkit'

class Child extends Parent
  classkit.extendsWithProto @

# ###
class Mixin extends classkit.Module
  @extendsWithProto().concern()

  @includedBlock: ->
    # will run in context of base class
    @instanceVariable 'test'

  class @ClassMethods
    someClassMethod: ->

  someInstanceMethod: ->

class Base extends classkit.Module
  @extendsWithProto().include Mixin

  @someClassMethod()

(new Base).someInstanceMethod()
```

## Why

`class ... extends ...` is implemented in coffee with

```coffee
for key of parent
  child[key] = parent[key]  if __hasProp_.call(parent, key)
```

It makes inheritance sticky.
* If you modify parent's property it would not be modified in child.
* Properties defined with `Object.defineProperty` would not be inherited.
* ...

## Solution

Use prototype chain for inheritance of class methods.

With `classkit.extendsWithProp @` default inheritance is redefined using
`child.__proto__ = parent`.

Ensure that you call this method before any class properties declarations,
'cause it'll drop'em all.

Once you use `extendsWithProto` you should use it on all descendents.

## Features

* It doesn't break into global namespace.
* Works on a top of usual coffee-script class declaration.
* Classes use prototypes chain.
* Full callbacks stack of Ruby-like inheritance model (`included`,
  `append_features`, `extend_object`, etc).
* Helpers to define ruby-like instance & class variables.
* `ActiveSupport::Concern`-like behaviour is optional.
* It works only 'cause of `__proto__`. Some say it's deprecated :)

## More examples

See source, tests & [costa](https://github.com/printercu/costa).

## License

BSD

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