JSFiddle - React, Tailwind, and code Playground
by rwaldron
HTML
<div id="moduleTest">
Output should go here: <ul id="outputUL"></ul>
</div>
JavaScript
log = function(msg)
{
$('#outputUL').append($('<li>'+msg+'</li>'));
}
loadTestModule = function()
{
log("onload handler called");
var tm1 = new TestModule1();
var tm2 = new TestModule2();
delete loadTestModule;
}
TestModule1 = function()
{
$(this).bind(
"customEvent",
$.proxy(this.customEventHandler, this)
);
$(this).trigger("customEvent");
}
TestModule1.prototype.customEventHandler = function()
{
log("Test Module 1 event triggered");
}
TestModule2 = function()
{
// uncomment this.length = 0 to make it not work
//this.length = 0;
$(this).bind(
"customEvent",
$.proxy(this.customEventHandler, this)
);
$(this).trigger("customEvent");
}
TestModule2.prototype.customEventHandler = function()
{
log("Test Module 2 event triggered");
}
$(loadTestModule);