public
Last active

  • Download Gist
infinite-jquery-event-loop.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(function($) {
 
var myTest;
 
function Test() {
$(Test).trigger("init.test");
}
Test.prototype.ready = function() {
$(this).trigger("ready.test");
};
$(Test).on("init", function() { console.log("Test init'ed"); });
myTest = new Test();
$(myTest).on("ready", function() { console.log("Test ready'ed"); });
myTest.ready();
 
})(jQuery);

This causes an infinate loop because when you call $(Test) it sees Test as a function and adds it to the document.ready event which is triggered and executed over and over and over and over and...

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.