Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lemaik/event-emitter
A tiny event emitter for javascript.
https://github.com/lemaik/event-emitter
Last synced: 2 days ago
JSON representation
A tiny event emitter for javascript.
- Host: GitHub
- URL: https://github.com/lemaik/event-emitter
- Owner: leMaik
- License: wtfpl
- Created: 2015-10-09T17:07:56.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-09T20:44:19.000Z (about 9 years ago)
- Last Synced: 2024-05-01T13:02:00.082Z (8 months ago)
- Language: CoffeeScript
- Size: 121 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# event-emitter
This is a tiny event emitter for JavaScript. You find a lot of these online, and
as I could not find one that would fit my needs (without having too many other
features), I made my own.## Usage
### Inherit from `event-emitter`
In CoffeeScript, you can inherit from `event-emitter` like this.
```coffee
EventEmitter = require 'event-emitter'
class MyClass extends EventEmitter
# ...
```### Add the event handler to an existing object
If your object already exists or if you don't use CoffeeScript or can't or don't
want to inherit from `event-emitter`, you can add the functions to an existing
object.
```js
var EventEmitter = require('event-emitter');
var myObject = { property: 'a' };
EventEmitter.installOn(myObject); //returns myObject
```
This adds `on`, `off` and `trigger` to your object, overwriting existing
properties.### Actually use the event emitter
*tl;dr: It works like every event emitter in JavaScript.** Add listeners with `.on('event name', handler)`
* Remove all event listeners for an event with `.off('event name')`
* Remove a specific event listener with `.off('event name', handler)`
* Remove all event listeners with `.off()`## License
This library (if 30 lines of code are enough to even call it a "library") is
licensed under the WTFPL. Do what you want...