Last active
December 12, 2015 02:09
-
-
Save rodrigo-x/4696833 to your computer and use it in GitHub Desktop.
pub/sub simples... jQuery...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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