jquery - Create a function / event for user in Javascript prototype -


i have protoype in project follows:

(function($) {      $.fn.observerpages = function(pageno) {       return new observerpage($(this), pageno);     };      function observerpage(parent, pageno) {       try {         this.parent = parent;         this.isinitialized = false;         this.timer = -1;         this.highchart = [];       } catch (e) {        }     }     observerpage.prototype = {       initialize: function(url) {         isinitialized = true;       },       update: function(controllerurl) {         if (isinitialized == true) {             //update           }         },         starttimer: function(url, interval) {},         stoptimer: function() {}       };     })(jquery); 

this initiates page hooked observer , gets data ajax service @ defined interval.

what require put event in user can put function when this.isinitialized becomes true.

currently using this.

var page = $("livediv").observerpages(2); page.initialize("http://localhost:5549/getlatestnews"); page.update("http://localhost:5549/getlatestnewsdata"); 

i want event user can handle when isinitialized gets true , can used this

page.oninitialize(function(){    //user writes function }); 

how can that?

solution might similar this:

var event = new event('pageinit'); observerpage.prototype = {   initialize: function(url) {     isinitialized = true;   },   update: function(controllerurl) {     if (isinitialized == true) {       document.dispatchevent(event);     }   },   starttimer: function(url, interval) {},   stoptimer: function() {},   oninitialize: function(callback)   {     document.addeventlistener('pageinit', callback, false);   } }; 

edit: this->document


Comments