Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 885 Bytes

prefer-event-target.md

File metadata and controls

39 lines (25 loc) · 885 Bytes

Prefer EventTarget instead of EventEmitter

This rule is part of the recommended config.

While EventEmitter could be used in only Node.js, EventTarget exist in Deno and Browser too.

This rule could potentially reduce the bundle size, and make your code more cross-platform friendly.

You can check their differences between EventEmitter and EventTarget.

Fail

import EventEmitter from 'node:event'

class Foo extends EventEmitter {

}
const emitter = new EventEmitter;

Pass

class Foo extends EventTarget {

}
const target = new EventTarget;