I need to create custom events in a javascript NameSpace, but i dont know if its possible.
I have a namespace like this:
NAMESPACE = {
var1 : 'value',
var2 : 'value',
initiate : function() {
console.log('initiate');
},
clear : function(arg) {
console.log('clear');
}
fail : function() {
// Here i need to trigger the error event..
}
}
That creates events using this method:
var myEvent = new CustomEvent("errorX", {
data: {
param: "value"
}
});
document.dispatchEvent(myEvent);
// In document.ready...
$(document).on('errorX', function(e) {
console.log(e);
});
This works, but I need to attach the addEventlistener to the document and I would like to attach this to the namespace object, like:
$(NAMESPACE).on('errorX', function(e) {
console.log(e);
});
It this possible?