I am seeking critique on what has become my normal methodology of writing JavaScript code. I have become heavily reliant on the jQuery library, but I think this has helped me learn the native language better also. Anyway, please critique the following style of JavaScript coding... Buried are a lot of questions of scope; if you could point out the strengths and weaknesses of this style I would appreciate it.
var critique ={
start: function(){
globalness = 'GLOBAL-GLOBAL'; //Available to all critique's methods
var notglobalness = 'LOCAL-LOCAL'; // Only available to critiques start method
//Am I using the "method" teminology properly here??
$('#stuff').on('click','a.closer-target',function(){
$target = $(this);
if($target.hasClass('active')){
$target.removeClass('active');
}
else{
$target.addClass('active');
critique.madness($target);
}
})
console.log(notglobalness+': at least I am useful at home');
console.log('note here that: '+notglobalness+' is no longer available after this point, lets continue on:');
critique.madness(notglobalness);
},
madness: function($e){
//Do a bunch of awesomeness with $e,
//but continue to keep it seperate because you think its best to keep things isolated.
//Send to the next function when complete here
console.log('Here is globalness, which is still available from the start method of critique!! ' + globalness);
console.log('Let us see if the globalness carries on to a new var object!!');
console.log('The locally isolated variable of NOTGLOBALNESS is available here, because it was passed to this method. Let us show it:'+$e);
carryOn.start();
}
} //end critique
var carryOn={
start: function(){
console.log('any chance critique.globalness will work here??? lets see: ' +globalness);
console.log('it absolutely does');
}
}
$(document).ready(critique.start);
(I always struggle with which of the Stack Exchange sites is best to post "questions of theory" like this, but I think Programmers is the best, if not, as usual a mod will move it, etc...)