Create Custom events in Namespaces
<p>I need to create custom events in a javascript NameSpace, but i dont know if its possible.</p>

<p>I have a namespace like this:</p>

<pre><code>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..
   }

}
</code></pre>

<p>Actually create events using this method:</p>

<pre><code>var myEvent = new CustomEvent("errorX", {
  data: {
    param: "value"
  }
});

document.dispatchEvent(myEvent);

// In document.ready...
$(document).on('errorX', function(e) {
   console.log(e);
});
</code></pre>

<p>This works, but i need to attach the addEventlistener to the "document" and i like to attach this to the namespace object, like:</p>

<pre><code>$(NAMESPACE).on('errorX', function(e) {
    console.log(e);
});
</code></pre>

<p>It is possible?
Thanks.</p>
