![](/style/images/good.png)
![](/style/images/bad.png)
How to implement Event Emitter in JavaScript? | Facebook Interview Question | De...
source link: https://devtools.tech/questions/s/how-to-implement-event-emitter-in-javascript-or-facebook-interview-question---qid---J4fNqXImp6QIdGMc7SPF
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to implement Event Emitter in JavaScript? | Facebook Interview Question
Create an event emitter that goes like this
var emitter = new Emitter();
Allows you to subscribe to some event
var sub1 = emitter.subscribe('function_name', callback1);
// you can have multiple callbacks to the same event
var sub2 = emitter.subscribe('function_name', callback2);
You can emit the event you want with this API (you can receive 'n' number of arguments)
emitter.emit('function_name', foo, bar);
And allows you to release the subscription like this (but you should be able to still emit from sub2)
sub1.release();
Recommend
-
200
Nano Events Simple and tiny event emitter library for JavaScript. Only 72 bytes (minified and gzipped). It uses Size Limit to control size....
-
90
-
52
README.md
-
8
Write your own compiler - Station #3: the emitter Feb 8, 2017 • Yehonathan Sharvit The plan Our
-
2
The Emitter Parameter Pattern for Flexible SPI Contracts Posted at May 4, 2020 For libraries and frameworks it’s a common requirement to make specific aspects customizeable via
-
4
Custom SVG Cursors with an Interactive Emitter Effect Several interactive cursor effects made with JavaScript and SVG. ...
-
6
eemit eemit is a Java event emitter library Install Maven: <dependency> <groupId>com.github.jafarlihi</groupId> <artifactId>eemit</artifactId> <version>0.1.0&l...
-
2
yarn add ueve # npm install ueve Concept μEve is designed to be as low-level and unopinionated as possible so you can build your own abstractions on top of it. It supports both sync and async modes. That mea...
-
5
tseep Because there are N fastest event emitters. And we are fastest (feb 2023) . Up to
-
4
How to use EventTarget as a web-native event emitterThis post is part of my Today I learned series in which I share all my web development learnings.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK