javascript publish subscribe with callback
<p>Scenario :- a json with checked &amp; unchecked item count needs to be sent to a common function which in turn does some basic validation or shows error. There are different function each handle by different css/js team which call this function &amp; depending on the common function result (true/false) each team/module that provided the json with check/uncheck status does the relevant action. Thus both common function (say getcount) &amp; every independent team calling this function rely on the result of common function manipulate the dom/css independently &amp; the common function too manipulate dom independently.</p>

<p>Instead of conventional way of calling function (say getCount({"chk" : 2 , "unchk" : 4})) i am looking for pusblish/subcribe method which is more cleaner as in Jquery &amp; easy to convey to all as only topic name &amp; contract/json needs to describe (also less if/else clause). Since common function is subscriber &amp; when every independent function publishes the resultant chk/unchek json the common function can easily do the manipulation using the publish/subscribe approach but the independent method has to do counter action as well which is only possible if subscribe function can send the result. I know javascript is asynchronous also i understand that common method can publish (say "resultOfGetCount") which every independent function/module can listen to &amp; do the action but is there any way in either in plain javascript or jquery where in on which subscriber can send the publisher the result in a way similar to $.ajax where in the callback function is called once server call is complete. </p>

<p>Looking for the best approach for such scenario.</p>
