Posted By

Nettuts on 01/26/11


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

scottshane
Roen
bostonbasso
qubestream


Elegant Pubsub with jQuery


 / Published in: JavaScript
 

  1. /*!
  2.  * jQuery Tiny Pub/Sub - v0.X - 11/18/2010
  3.  * http://benalman.com/
  4.  *
  5.  * Original Copyright (c) 2010 "Cowboy" Ben Alman
  6.  * Dual licensed under the MIT and GPL licenses.
  7.  * http://benalman.com/about/license/
  8.  *
  9.  * Made awesome by Rick Waldron
  10.  *
  11.  */
  12.  
  13. (function(jQuery){
  14. var o = jQuery({});
  15. jQuery.each({
  16. "subscribe" : "bind",
  17. "unsubscribe" : "unbind",
  18. "publish" : "trigger"
  19. }, function ( fn, api ) {
  20. jQuery[ fn ] = function() {
  21. o[ api ].apply( o, arguments );
  22. };
  23. });
  24. })(jQuery);

Report this snippet  

You need to login to post a comment.