# eventobj

> Basiclly Object.create() with some added event related features

Latest version **1.1.3** (published 2018-10-08) · MIT license · 0 weekly downloads

## Install

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

## 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.1.3 |
| Published | 2018-10-08 |
| First published | 2018-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 159.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Petter Ahlberg |
| Maintainers | petterboozegunk |

## Links

- npm: https://www.npmjs.com/package/eventobj
- Repository: https://github.com/PetterBoozegunk/eventObject
- Homepage: https://github.com/PetterBoozegunk/eventObject#readme
- Issues: https://github.com/PetterBoozegunk/eventObject/issues
- npm.io page: https://npm.io/package/eventobj

## Recent versions

- 1.1.3 (latest) — 2018-10-08
- 1.1.1 — 2018-03-16
- 1.1.0 — 2018-03-16
- 1.0.1 — 2018-02-13

## README

# eventObject
Usage is basically the same as for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create">Object.create()</a>.
With some added features.

```js
const eventObject = require("eventobj");

let myEventObject = eventObject.create(prototypeObject[, propertiesObject]);
```

## methods
The new eventObject will get a number of new methods. 

### on
Adds an eventlistener to the object.

Usage:
```js
myEventObject.on("myEvent", function () {
  // 'this' will be bound the 'myEventObject' object
});
```

### off
Removes an eventlistener to the object.
To remove a listener it has to be a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a>.

Usage:
```js
myEventObject.off("myEvent", '[function expression]');
```

### trigger
Triggers an eventlistener.<br> 
Takes an, optional, second "context" (object) argument that 'this' will be bound to. 

Usage:
```js
myEventObject.trigger("myEvent"[, contextObject]);
```

### addChild
Adds a childnode the the object. The child object will also be an eventObject.
This will make DOM-like bubbling possible.
When an event is triggered on the childObject it will bubble to its parent.

The childObject will also get a "bubblesTo" array that can be used for "non hierarchyal" bubbling.

Usage:
```js
myEventObject.addChild("newChildName", newChildObject);
```

### listeners
Returns an array containg the listeners for the specified event.
If there is no listeneners it returns an empty array.

Usage:
```js
let listeners = myEventObject.listeners("myEvent");
```

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