Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dex4er/js-events.off
Polyfill/shim for events.EventEmitter.prototype.off in node versions < v10
https://github.com/dex4er/js-events.off
Last synced: 11 days ago
JSON representation
Polyfill/shim for events.EventEmitter.prototype.off in node versions < v10
- Host: GitHub
- URL: https://github.com/dex4er/js-events.off
- Owner: dex4er
- License: mit
- Created: 2018-08-16T20:11:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-16T20:32:38.000Z (over 6 years ago)
- Last Synced: 2024-10-28T09:00:55.303Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# events.off
[![Build Status](https://secure.travis-ci.org/dex4er/js-events.off.svg)](http://travis-ci.org/dex4er/js-events.off) [![npm](https://img.shields.io/npm/v/events.off.svg)](https://www.npmjs.com/package/events.off)
Polyfill for events.EventEmitter.prototype.off in node versions < v10
node v10.0.0 added support for a built-in `events.EventEmitter.prototype.off`:
This package provides the built-in `events.EventEmitter.prototype.off` in node
v10.0.0 and later, and a replacement in other environments.This package implements the [es-shim API](https://github.com/es-shims/api)
interface. It works in an ES3-supported environment and complies with the
[spec](http://www.ecma-international.org/ecma-262/6.0/).## Usage
### Direct
```js
const off = require('events.off');
// Use `off` just like the built-in method on `events.EventEmitter.prototype`
const events = require('events');
const emitter = new events.EventEmitter();
const handler = () => {};
emitter.on('foo', handler);
// Use `off`
off(emitter, 'foo', handler);
```### Shim
```js
require('events.off/shim')();
// `events.EventEmitter.prototype.off` is now defined
const events = require('events');
const emitter = new events.EventEmitter();
const handler = () => {};
emitter.on('foo', handler);
// Use `emitter.off`
emitter.off('foo', handler);
```or:
```js
require('events.off/auto');
// `events.off` is now defined
const events = require('events');
const emitter = new events.EventEmitter();
const handler = () => {};
emitter.on('foo', handler);
// Use `emitter.off`
emitter.off('foo', handler);
```