Skip to content

Instantly share code, notes, and snippets.

Avatar

tradewind2018

View GitHub Profile
@tradewind2018
tradewind2018 / pubsub.js
Created Mar 14, 2018 — forked from learncodeacademy/pubsub.js
Basic Javascript PubSub Pattern
View pubsub.js
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {