A quick look at how to implement pub sub technique using jQuery’s on and off functions.

Related Posts:

/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
 * http://benalman.com/
 * Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */

(function($) {

  var o = $({});

  $.subscribe = function() {
    o.on.apply(o, arguments);

  $.unsubscribe = function() {
    o.off.apply(o, arguments);

  $.publish = function() {
    o.trigger.apply(o, arguments);


source: https://gist.github.com/661855

How it works and how to use it? Working example: http://jsfiddle.net/cowboy/HvAJf/

Sam Deering Sam Deering
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

No Reader comments

Stay ahead of the game Exclusive content for developers and digital experts Go Premium