sindresorhus/emittery

Add convenience method to bind Emittery methods to own instance #30

sindresorhus posted onGitHub

EventEmitter in Node.js is usually subclassed, but I don't like this pattern, and I don't think we should recommend it. It's better to have an internal Emittery instance and just explicitly expose some of the methods.

We could make this even easier, by providing a convenience method to bind the Emittery method to the instance:

class Foo {
    constructor() [
        this.emitter = new Emittery();
        this.emitter.bindMethods(this, ['on', 'off']);
    ]
}

The above would quickly expose the on and off methods, but nothing else.


Fund this Issue

$60.00
Rewarded

Rewarded pull request

Recent activities

stroncium was rewarded by sindresorhus for sindresorhus/emittery# 30
almost 6 years ago
stroncium submitted an output to  sindresorhus/ emittery# 30
about 6 years ago