Use this to add events to your objects without needing any libaries.
Simple function can be imported or copy pasted. In your object constructor
assign your event functions to the return value of the createCustomEvent()
.
Simple example:
<script src="createCustomEvent.js" type="text/javascript"></script>
Then in your object definition code:
// Define
function MyObject() {
this.onCustomEvent = createCustomEvent();
}
MyObject.prototype.test = function() {
this.onCustomEvent("message");
};
// Add listeners
var instance = new MyObject();
instance.onCustomEvent( function(msg) {
alert(msg);
} );
// Run
instance.test();
See it working at jsbin.com.