There are two (known today) very subtle bugs coming from my latest bright ideas about professional JavaScript. Actually thereâs one bug today the other is a design âissue.â The bug is characterized by a click event that fires and firesâlike itâs in a loop. I wasted many hours (at âhomeâ and in the W2 labor camp) trying to look for loops. No dice.
It turns out (Jâah provides) that my Display Builder pattern did not account for running display builder procedures once at load time instead of again and again. Iâm not going to take the time (this month) to find the exact proof of this but it appears that âwiring upâ events repeatedly with YUI can cause them to fire repeatedly.
The second issue (bug?) has to do with Firebug. You see, my interpretation of Douglas Crockfordâs module pattern (published in JavaScript: The Good Parts which slightly different from the YUI pattern) means my code is full of this stuff:
(function(){
SONGHAY.ui.Client =
{
//use âselfâ instead of âthisâ in hereâŠ
};
var self = SONGHAY.ui.Client;
})();
According to Dougâs jslint.com, the variable self is not of a closure. This is because it appears after the object literal, SONGHAY.ui.Client. In fact, the variable self is marked âunusedâ by jslint.com (but, when the variable self appears inside of SONGHAY.ui.Client, it is not marked as an implied globalâuntil further notice, this little detail is very important to me).
When debugging this stuff in Firebug, the variable self is assigned to âWindowââwhich I assume is a bug or me writing crappy JavaScript. I am not afraid to be told that I am writing crappy codeâso any person reading this (with some documentation to back them up) please do take the time to inform me instead of snickering to yourself like a punk-ass Church mouse and moving on⊠I assure you: you will not be wasting your time⊠You see how deprecating I am when asking for help?
The question âweâ might ask here is, âWhy are you trying to avoid using the keyword this?â Here are a few links that cover the this issue:
- âJavascriptâThe this keywordâ
- âA better understanding of JavaScriptâ Alexander Kirk: âIf you call this function from within a HTML page via an
onclickevent, this is refers to the calling object (i.e. the link).â - âJavascript TutorialâWhy The this Keyword Breaksâ The Tallest: âThe
thiskeyword is never null or undefined in javascriptâit always defaults back to pointing at the global object (in browsers this would be the window object).â
