# coffee-eventemitter

> simple EventEmitter

Latest version **1.0.0** (published 2016-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install coffee-eventemitter
pnpm add coffee-eventemitter
yarn add coffee-eventemitter
bun add coffee-eventemitter
```

## 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.0 |
| Published | 2016-04-09 |
| First published | 2016-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | CoffeeDeveloper |
| Maintainers | flyme |
| Keywords | eventemitter |

## Links

- npm: https://www.npmjs.com/package/coffee-eventemitter
- Repository: https://github.com/coffeedeveloper/coffee-eventemitter
- Homepage: https://github.com/coffeedeveloper/coffee-eventemitter#readme
- Issues: https://github.com/coffeedeveloper/coffee-eventemitter/issues
- npm.io page: https://npm.io/package/coffee-eventemitter

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-04-09

## README

# 一个简易的事件对象

专门用于给对象添加订阅事件功能

## API说明

### 初始化

原生对象继承

```js
var foo = Object.create(SimpEvent);

//如果是比较低级一点的浏览器或者说有用到jQuery或者lodash之类的类库，可以用extend方法
var boo = $.extend({}, SimpEvent);
var bar = _.extend({}, SimpEvent);
```

函数继承
```js
function Foo() {
}

Foo.prototype = SimpEvent;
Foo.prototype.constructor = Foo;

var foo = new Foo();
```


### on

注册事件监听事件，`on(事件名称，处理函数)`

```js
foo.on('test', function() {
  console.log(arguments);
});
```

### once

同`on`，只是会触发一次

### off

取消监听事件，`off(事件名称，处理函数)`，如果不带处理函数则取消该事件下的所有监听函数。

特别注意**匿名函数**是不可以取消的。

```js
function haha() {}

foo.on('haha', haha);
foo.off('haha', haha);
```

### emit

触发监听函数，`emit(事件名称, 参数)`。

```js
foo.emit('haha', 1, 2, 3);
```

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