Style, CSV documenting etc.

Browser scripting
KBleivik
Site Admin
Posts: 178
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway
Contact:

Style, CSV documenting etc.

Postby KBleivik » Tue Aug 16, 2011 1:04 pm

1. Javascript best practices.

What is the best coding practice in one language may be bad in another language. Some suggest that you should not use tabs to ident code in JavaScript. Instead they mean that using two spaces is best. In PHP underscores is often used in variable names. In JavaScript the preferred method is camelCase. Here

Use the strong equality operator === instead of ==: http://net.tutsplus.com/tutorials/javas ... beginners/

http://dev.opera.com/articles/view/java ... practices/

http://www.javascripttoolbox.com/bestpractices/


2. CVS - Concurrent Versioning System

Every JavaScript file should have a comment at the top that has the contents $Id$ like this

Code: Select all

// $Id$


Read more: http://www.nongnu.org/cvs/

3. Document your JavaScript code.

One recommended way to comment your code is as shown in this add.js file

add.js

Code: Select all

//$Id$
/**
 * Add two numbers together.
 */

/**
 *  Add two numbers.
 * 
 *  This function adds two numbers together and returns the sum.
 *
 *  @param a
 *    The first number
 *  @param b
 *    The second number
 *  @return
 *    The sum of a and b
 */
function sum(a,b) {
  return a+b;
}

Where we have added one comment for the file and one comment for the function. In addition, note the content $Id$ comment at the top.

For further information see:

http://metajack.wordpress.com/2008/07/0 ... ion-tools/

http://www.stack.nl/~dimitri/doxygen/

http://www.stack.nl/~dimitri/doxygen/helpers.html

http://jayxie.com/doxygen-js/use-doxyge ... javascript

Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest