I want to simulate C#'s events in JavaScript: what i want to do is something like this:
Let's say i have the following code:
function addToInvocationList(method, listener) {
*Some code to add listener to the invocation list of method*
}
function MyClass() {
}
MyClass.prototype.Event = function() {}
var my_class_obj = new MyClass();
function subscriberFunction1() {}
function subscriberFunction2() {}
function subscriberFunction3() {}
addToInvocationList(my_class_obj.Event, subscriberFunction1);
addToInvocationList(my_class_obj.Event, subscriberFunction2);
addToInvocationList(my_class_obj.Event, subscriberFunction3);
my_class_obj.Event();
What i want to do is when i call my_class_obj.Event, all the subscribed functions get called.
Could this be achieved purely in JavaScript or i need to find my way around through DOM events?