Skip to content

Instantly share code, notes, and snippets.

@rodrigo-x
Last active December 12, 2015 02:09
Show Gist options
  • Save rodrigo-x/4696833 to your computer and use it in GitHub Desktop.
Save rodrigo-x/4696833 to your computer and use it in GitHub Desktop.
pub/sub simples... jQuery...
/**
* pub/sub
*/
var EventDriven = {
/**
* Adiciona um evento
* @param {String} event O evento que será disparado.
* @param {Function} callback
*/
subscribe: function(event, fn) {
$(this).on(event, fn);
},
/**
* Responsável por nomear o evento
* @param {String} event O evento que será renomeado.
*/
publish: function(event) {
$(this).trigger(event);
}
};
EventDriven.subscribe("QualquerPOrcaria", function() {
alert('QualquerPorcaria!');
});
EventDriven.publish("QualquerPOrcaria");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment