Elegant Pubsub with jQuery


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.