Skip to content

Instantly share code, notes, and snippets.

View ashwanisindhu-2's full-sized avatar

ashwanisindhu-2

View GitHub Profile
@ashwanisindhu-2
ashwanisindhu-2 / events.js
Created June 11, 2021 12:14 — forked from h9h/events.js
Minimal Event/Emitter Implementation
module.exports = () => ({
events: { },
emit(event, ...args) {
(this.events[event] || []).forEach(i => i(...args))
},
on(event, cb) {
(this.events[event] = this.events[event] || []).push(cb)
return () => (
this.events[event] = this.events[event].filter(i => i !== cb)
)
@ashwanisindhu-2
ashwanisindhu-2 / events.js
Created June 11, 2021 12:12 — forked from ashwanisindhu1/events.js
Minimal Event/Emitter Implementation
module.exports = () => ({
events: { },
emit(event, ...args) {
(this.events[event] || []).forEach(i => i(...args))
},
on(event, cb) {
(this.events[event] = this.events[event] || []).push(cb)
return () => (
this.events[event] = this.events[event].filter(i => i !== cb)
)
@ashwanisindhu-2
ashwanisindhu-2 / Classes.js
Created June 11, 2021 05:19 — forked from gaearon/Classes.js
Beneath Classes: Prototypes
class Spiderman {
lookOut() {
alert('My Spider-Sense is tingling.');
}
}
let miles = new Spiderman();
miles.lookOut();