I am working with a bit of code which has the following Javascript function. I have read this SO article which has explained things a little bit but I am still a bit confused as to how this code works.
The code is as follows:
messageBus = (function() { var messages = {}; function publish(name, data) { //does some stuff } function subscribe(name, callback) { //does some stuff } function unsubscribe(name, callback) { //does some stuff } return { publish:publish, subscribe:subscribe, unsubscribe:unsubscribe }; })(); And then is called by
messageBus.publish("Submit"); What does the
return { publish:publish, subscribe:subscribe, unsubscribe:unsubscribe }; bit do in the code do?
publish,subscribeandunsubscribe. See developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…