# troop

> Full-featured, testable OOP

Latest version **0.9.0** (published 2015-07-10) · MIT license · 0 weekly downloads

## Install

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

## 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.9.0 |
| Published | 2015-07-10 |
| First published | 2013-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dan Stocker |
| Maintainers | danstocker |
| Keywords | oop, class, classical, inheritance, trait, traits, testing, mocks, memoization, surrogate, surrogates |

## Links

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

## Dependencies (1)

- [dessert](https://npm.io/package/dessert.md) ~0.3.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.9.0 (latest) — 2015-07-10
- 0.8.1 — 2015-06-29
- 0.8.0 — 2014-12-04
- 0.7.2 — 2013-12-27
- 0.7.1 — 2013-12-16
- 0.7.0 — 2013-08-25
- 0.6.1 — 2013-08-11
- 0.6.0 — 2013-08-05
- 0.5.1 — 2013-06-22
- 0.5.0 — 2013-06-16
- 0.4.0 — 2013-06-13
- 0.3.9 — 2013-06-03
- 0.3.8 — 2013-05-26
- 0.3.7 — 2013-05-24
- 0.3.6 — 2013-05-24
- … 5 more at https://npm.io/package/troop/versions

## README

Troop
=====

*Full-featured, testable OOP*

[Wiki](https://github.com/production-minds/troop/wiki)

[Reference](http://production-minds.github.io/troop/)

Troop features
--------------

- multiple inheritance with traits
- makes use of ES5 property attributes
    - pseudo-privates are non-enumerable
    - constants are actually read-only
- testing mode for applying mock methods
- postponed, on-demand property definitions
- delegation of instantiation with surrogates
- support for instance memoization

Troop is distinguished from other OOP-related libs such as MooTools or Backbone by

- not littering *your* classes and instances with its own meta-properties
- non-declarative API leads to better IDE integration
- offering simpler unit testing with built-in mocks to speed up TDD process

Example
-------

    var MyClass = troop.Base.extend()
        .addPrivate({
            _secret: "ufo" // static private property
        })
        .addPublic({
            hello: "world" // static public property
        })
        .addConstants({
            pi: 3.14 // static public constant
        })
        .addMethods({
            init: function (who) {
                this.addPublic({
                    hello: who
                });
            }
        });

    var myInstance = MyClass.create("all");

![myInstance in console](https://dl.dropboxusercontent.com/u/9258903/myInstance-0.4.0.png)

Check out these jsFiddles for more examples:

- [Using Troop](http://jsfiddle.net/danstocker/n5jze/)
- [Postponed property definitions](http://jsfiddle.net/danstocker/YR374/)
- [Surrogate classes in Troop](http://jsfiddle.net/danstocker/ZsZGy/)

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