How do I create a custom event for a javascript class?
Example Code
function somefunction(url){
this.h_world = function(){/*some random code to do*/ };
}
var hw = new somefunction();
Now, for a very simple example, how do I create a custom event handler for this when hw.h_world
has finished executing and return some data with it?
For example
var hw = new somefunction();
hw.h_world();
hw.finished_h_world = function(somedata){
alert(somedata);
}
What you need is a callback function:
And then:
Here is a jsfiddle: http://jsfiddle.net/remibreton/xzeEd/
you can pass a callback function to h_world function and execute it on finish of it
or you can add a function to your class like this