Closure coding convention suggestion - Ext JS

Hi Jack,

I'm certainly not as productive / good as you are (that's an overstatement, I'm way way less productive than you are) but while reading your code there are certain things I wish you'd have done that will make life much easier for the reader.

In many occassion you'd use a closure to protect the local variables when you define a top level objects

For instance while I was reading EventManager.js

at the beginning I see

Ext.EventManager = function(){
 .............
 600 lines below
}
At first glance I was thinking that this

function(){...}
is the constructor of Ext.EventManager.

Not until I see something like
var pub = {.........}
I start to feel strange and then at at line 321 I see

return pub;
Of course at line 322 we can cleanly see that it is a closure.

}();

So my humble opinion is that if we wrap the function{} literal in parenthesis then it would be very clear from the start that it is not a constructor but a closure.

So instead of

function() {
......
600 lines
......
}();
this would be much easier to read.

(function() {
......
600 lines
......
})();
I hope this makes sense. Maybe 10 years later this will help you pickup ext1.0 again faster :-)
  # 2  
03-06-2007, 08:15 PM

Considering how I am constantly trying to trim bytes, adding extra ones that serve no purpose doesn't look too appealing. At the top of the file and in the docs it is defined with @singleton (right before the closure starts) which should signal for you that it is a closure (since it can't be a constructor).

你可能感兴趣的:(ext)