\href{https://www.npmjs.com/package/eventemitter3}{\texttt{ }}\href{https://travis-ci.org/primus/eventemitter3}{\texttt{ }}\href{https://david-dm.org/primus/eventemitter3}{\texttt{ }}\href{https://coveralls.io/r/primus/eventemitter3?branch=master}{\texttt{ }}\href{https://webchat.freenode.net/?channels=primus}{\texttt{ }}

\href{https://saucelabs.com/u/eventemitter3}{\texttt{ }}

Event\+Emitter3 is a high performance Event\+Emitter. It has been micro-\/optimized for various of code paths making this, one of, if not the fastest Event\+Emitter available for Node.\+js and browsers. The module is API compatible with the Event\+Emitter that ships by default with Node.\+js but there are some slight differences\+:


\begin{DoxyItemize}
\item Domain support has been removed.
\item We do not {\ttfamily throw} an error when you emit an {\ttfamily error} event and nobody is listening.
\item The {\ttfamily new\+Listener} and {\ttfamily remove\+Listener} events have been removed as they are useful only in some uncommon use-\/cases.
\item The {\ttfamily set\+Max\+Listeners}, {\ttfamily get\+Max\+Listeners}, {\ttfamily prepend\+Listener} and {\ttfamily prepend\+Once\+Listener} methods are not available.
\item Support for custom context for events so there is no need to use {\ttfamily fn.\+bind}.
\item The {\ttfamily remove\+Listener} method removes all matching listeners, not only the first.
\end{DoxyItemize}

It\textquotesingle{}s a drop in replacement for existing Event\+Emitters, but just faster. Free performance, who wouldn\textquotesingle{}t want that? The Event\+Emitter is written in Ecma\+Script 3 so it will work in the oldest browsers and node versions that you need to support.\hypertarget{md_sfcode_node_modules_eventemitter3_README_autotoc_md9285}{}\doxysection{Installation}\label{md_sfcode_node_modules_eventemitter3_README_autotoc_md9285}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/-\/save eventemitter3 }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_eventemitter3_README_autotoc_md9286}{}\doxysection{CDN}\label{md_sfcode_node_modules_eventemitter3_README_autotoc_md9286}
Recommended CDN\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{https://unpkg.com/eventemitter3@latest/umd/eventemitter3.min.js }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_eventemitter3_README_autotoc_md9287}{}\doxysection{Usage}\label{md_sfcode_node_modules_eventemitter3_README_autotoc_md9287}
After installation the only thing you need to do is require the module\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var EventEmitter = require('eventemitter3'); }

\end{DoxyCode}


And you\textquotesingle{}re ready to create your own Event\+Emitter instances. For the API documentation, please follow the official Node.\+js documentation\+:

\href{http://nodejs.org/api/events.html}{\texttt{ http\+://nodejs.\+org/api/events.\+html}}\hypertarget{md_sfcode_node_modules_eventemitter3_README_autotoc_md9288}{}\doxysubsection{Contextual emits}\label{md_sfcode_node_modules_eventemitter3_README_autotoc_md9288}
We\textquotesingle{}ve upgraded the API of the {\ttfamily Event\+Emitter.\+on}, {\ttfamily Event\+Emitter.\+once} and {\ttfamily Event\+Emitter.\+remove\+Listener} to accept an extra argument which is the {\ttfamily context} or {\ttfamily this} value that should be set for the emitted events. This means you no longer have the overhead of an event that required {\ttfamily fn.\+bind} in order to get a custom {\ttfamily this} value.


\begin{DoxyCode}{0}
\DoxyCodeLine{var EE = new EventEmitter()}
\DoxyCodeLine{  , context = \{ foo: 'bar' \};}
\DoxyCodeLine{}
\DoxyCodeLine{function emitted() \{}
\DoxyCodeLine{  console.log(this === context); // true}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{EE.once('event-\/name', emitted, context);}
\DoxyCodeLine{EE.on('another-\/event', emitted, context);}
\DoxyCodeLine{EE.removeListener('another-\/event', emitted, context); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_eventemitter3_README_autotoc_md9289}{}\doxysubsection{Tests and benchmarks}\label{md_sfcode_node_modules_eventemitter3_README_autotoc_md9289}
This module is well tested. You can run\+:


\begin{DoxyItemize}
\item {\ttfamily npm test} to run the tests under Node.\+js.
\item {\ttfamily npm run test-\/browser} to run the tests in real browsers via Sauce Labs.
\end{DoxyItemize}

We also have a set of benchmarks to compare Event\+Emitter3 with some available alternatives. To run the benchmarks run {\ttfamily npm run benchmark}.

Tests and benchmarks are not included in the npm package. If you want to play with them you have to clone the Git\+Hub repository. Note that you will have to run an additional {\ttfamily npm i} in the benchmarks folder before {\ttfamily npm run benchmark}.\hypertarget{md_sfcode_node_modules_eventemitter3_README_autotoc_md9290}{}\doxysection{License}\label{md_sfcode_node_modules_eventemitter3_README_autotoc_md9290}
\mbox{[}MIT\mbox{]}(LICENSE) 