Showing posts with label Observer Design Pattern. Show all posts
Showing posts with label Observer Design Pattern. Show all posts

Saturday, January 18, 2014

Observer Design Pattern in Jquery


We can use observer design pattern (publisher - subscriber model) in jquery by triggering and attaching events.
Attach a trigger event for publisher
$('div').on('click', function(e) {
    $(this).trigger('MyEvent',e,parameterValue);
});


Attach subscriber methods
$(document).on('MyEvent', function(e,parameterValue) {
    //Do your stuffs with parameterValues..
});
Read More
Powered By Blogger · Designed By Seo Blogger Templates