Added by Cameron Shorter, last edited by Andreas Hocevar on Jan 27, 2008  (view change)

Labels

 
(None)
  1. Maintain your JSDoc comments. These are important for future maintainers. JSDocis a tool that parses inline documentation in JavaScript source files, and produces HTML documentation of the JavaScript code. JSDoc is similar to the java based javadoc tool.
  2. Use 2 space indents without tab chars. You may need to change the settings on your editor.
    1. For vi or vim, update .vimrc with the following:
      .vimrc
      set expandtab
      set shiftwidth=2
      3. Use the correct for-loops. When looping through an object or a hash map, you have to use
      for (var key in object) {
         // do something with object[key]
      
      When looping through an array (i.e. something with a length and only numeric keys), you have to use
      for (var i=0; i<array.length; i++) {
        // do something with array[i]
      
      Failure to do so will cause trouble when using JS frameworks that override the Array object.