The EventTarget() constructor creates objects that can listen for and fire events (same API as MDN EventTarget()). You already use EventTarget every day on window, document, and HTML elements. This tutorial shows how to build your own emitters with new EventTarget(), extends EventTarget, and CustomEvent — with five examples and try-it labs.
01
Create
new EventTarget()
02
Extend
class X extends EventTarget
03
Listen
addEventListener
04
Fire
dispatchEvent
05
Data
CustomEvent
06
Workers
Supported
Fundamentals
Introduction
Buttons, inputs, and the window object can all call addEventListener because they implement the EventTarget interface.
With new EventTarget() you get that same ability on a plain JavaScript object — useful for counters, stores, game entities, or any model that should notify listeners when something changes.
💡
Typical pattern
MDN notes you rarely call the constructor alone. More often you extends EventTarget and call super() in your class constructor so instances inherit the event methods.
Continue with Window methods after you understand custom emitters — DOM objects are EventTargets too.
Concept
Understanding the EventTarget Constructor
Calling new EventTarget() returns a new object with the standard event methods. No arguments are required.
addEventListener(type, listener) — register a handler.
removeEventListener(type, listener) — unregister the same function reference.
dispatchEvent(event) — fire an Event or CustomEvent.
Subclass with extends EventTarget and call super() first.
Perfect for initialization signals. The listener fires on the first matching event and then unregisters itself.
Applications
🚀 Common Use Cases
App models — counters, carts, and settings that notify the UI.
Mini event buses — decouple modules with typed custom events.
Game / animation objects — fire spawn, hit, done without DOM nodes.
Workers — same listen/dispatch pattern off the main thread.
Teaching the DOM event model — practice without needing HTML first.
Not a replacement for framework stores — use when native events are enough.
🧠 How new EventTarget() Works
1
Construct the target
new EventTarget() or super() in a subclass.
Create
2
Register listeners
Map event type strings to callback functions.
Listen
3
Dispatch an event
Create Event / CustomEvent and call dispatchEvent.
Fire
4
✅
Handlers run in order
Matching listeners receive the event object (and detail if set).
Important
📝 Notes
Always call super() before using this in a subclass constructor.
Event type names are case-sensitive strings ("valuechange" ≠ "ValueChange").
Keep function references if you plan to call removeEventListener.
dispatchEvent is synchronous — listeners run before the next line continues.
Available in Web Workers (per MDN).
DOM nodes already are EventTargets — you do not wrap a button in new EventTarget().
Compatibility
Universal Browser Support
The constructible EventTarget() API is Baseline Widely available in modern browsers (roughly since 2020). It is also available in Web Workers. Internet Explorer does not support new EventTarget().
✓ Baseline · Widely available
EventTarget() constructor
Safe in modern Chrome, Firefox, Safari, and Edge. Prefer extends EventTarget + super() for custom emitters.
ModernWidely available
Google Chrome64+ · Desktop & Mobile
Full support
Mozilla Firefox59+ · Desktop & Mobile
Full support
Apple Safari14+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Internet ExplorerNot supported · Use a polyfill
No support
Opera51+ · Modern versions
Full support
EventTarget()Excellent in modern browsers
Bottom line: Use new EventTarget() or class extends EventTarget. Pair with CustomEvent for payloads. Not available in Internet Explorer without a polyfill.
Wrap Up
Conclusion
The EventTarget() constructor gives any object the same listen/dispatch API as the DOM. Create a target with new EventTarget(), or more often extends EventTarget and call super(), then fire CustomEvents when state changes.
Store listener references when you need to remove them
Prefer { once: true } for one-shot setup events
❌ Don’t
Forget super() in an extends EventTarget class
Expect anonymous listeners to be removable later
Mix up event type spelling between listen and dispatch
Assume Internet Explorer supports new EventTarget()
Wrap DOM elements in another EventTarget unnecessarily
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the EventTarget constructor
Build custom emitters with the same API as the DOM.
5
Core concepts
📄01
Create
new EventTarget()
API
📚02
Extend
super()
Class
🔊03
Listen
addEventListener
Pattern
🔥04
Fire
dispatchEvent
Emit
📦05
Data
CustomEvent
detail
❓ Frequently Asked Questions
new EventTarget() creates a plain object that can listen for and dispatch events using addEventListener, removeEventListener, and dispatchEvent — without being a DOM element.
Rarely. Most often you call super() inside a class that extends EventTarget, so your own objects can fire custom events. MDN notes explicit new EventTarget() is uncommon outside that pattern.
Elements like button or document already implement EventTarget. The constructor lets you build non-DOM objects (stores, counters, services) that speak the same event API.
Any Event or CustomEvent. CustomEvent is popular because detail can carry data, for example new CustomEvent("valuechange", { detail: 42 }).
Yes. MDN marks the constructor as available in Web Workers, so you can use the same listen/dispatch pattern off the main thread.
It is Baseline Widely available in modern Chrome, Firefox, Safari, and Edge. Internet Explorer does not support constructing EventTarget. Polyfills exist for older environments.
Did you know?
Before constructible EventTarget landed in browsers, developers often attached a hidden DOM node or wrote tiny pub/sub libraries just to get addEventListener-style APIs on plain objects.