# es6-trait-implementer

> Simple trait functionality for ES6 classes

Latest version **1.0.1** (published 2017-06-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install es6-trait-implementer
pnpm add es6-trait-implementer
yarn add es6-trait-implementer
bun add es6-trait-implementer
```

## 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.0.1 |
| Published | 2017-06-27 |
| First published | 2017-06-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jake Taylor |
| Maintainers | pcfutures |

## Links

- npm: https://www.npmjs.com/package/es6-trait-implementer
- npm.io page: https://npm.io/package/es6-trait-implementer

## Recent versions

- 1.0.1 (latest) — 2017-06-27
- 1.0.0 — 2017-06-27

## README

# ES6 Trait Implementer

This is a very easy to use, lightweight library that implements class traits, much like PHP's traits.

## Install

Install via npm:
`npm i --save es6-trait-implementer`

## Usage

The library works by calling a function on a class before you use it, similar to how Higher-order-components (HOCs) work in React.

### Main Class
This would be your class that you want to implement traits on, see below to see how to define traits.
```JavaScript
import implementsTraits from 'es6-trait-implementer'; // Import the library first
import { GreetingTrait } from '...'; // Import your traits

// Have a class you want to use traits on
class MyClass {
    constructor () {
        this.greet();
    }
}

// Call the libraries function on the class with an array of traits
MyClass = implementsTraits(MyClass, [GreetingTrait]);

// Then use your class!
const myClass = new MyClass(); // Logs 'Hello, world!' to console
```

### Trait Example
Traits are simply classes:
```JavaScript
class GreetingTrait {
    greet () {
        console.log('Hello, world!');
    }
}

export { GreetingTrait }; // Don't forget to export!
```

Done!

Of course, you can export/import anyway you like, i.e `export default class Trait { }` with `import Trait from '...'` works fine, too.

## Notes

Feel free to open up issues/pull requests if you find any problems.

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