Jetty Java Coding Standards
Use objects rather than functions.
we should write:
Private fields and functions should have names starting with '_'.
Note that this is a very light weight form of object and we are not using any concept of class. It is equivalent to a javaclass of static members and simply groups related functions together for name space clarity.
JS files as packages
Use semicolon to end statements
I know it is optional, but it makes it easier for old C-hacks to parse as well as making it easier for the interpretors to spot errors if a typo is made.
Use the behaviour library
Unique Id's, multiple classes
The ID of a DOM element must be unique, while multiple DOM elements can have the same class. A frequent mistake is to use a non unique id, for example on a cell in a table (if the table has multiple rows then a cell id is not unique). A class should be used if there are visual ramifications, otherwise normal attributes or external associative arrays should be used.
The this automatic field in js works differently to java. If a member function of an object is called as a callback, then the this does not refer to the object but the calling scope. For example in the following code:
the _handle method is called when the mybutton is clicked, but the
this will not refer to the
myhandler object, but rather the DOM element of the button! The object var
myhandler can be used instead of
this in these circumstances.
Use 'single' instead of "double" quotes
Use var keyword for variables inside for loop
I know this is supposed to be optional but IE does not seem to handle well for loops with variables that are not declared with var. Thus instead of writing:
we should write: