Skip to content

Instantly share code, notes, and snippets.

@DanielG
Created December 29, 2010 20:04
Show Gist options
  • Save DanielG/758995 to your computer and use it in GitHub Desktop.
Save DanielG/758995 to your computer and use it in GitHub Desktop.
Unhosted.js coding guidelines
  • 4 space indentation

  • 80 character max per line

  • if's always have space before braces

  • if's always have braces

    if() {
      return;
    }
    
    • exception: if(err) throw err;
  • else aligns with if's closing brace

    if() {

    } else {

    }

  • multi command ifs must be multi line

    if(bla) {
        bla;
        doubleBla;
    }
    
    • exception: if(err) { callback(err); return; }
  • function definitions never have spaces before brackets

  • function definitions have a space before the opening brace function() { return; }

    or
    
    function bla() {
        return;
    }
    
    • exception: single line/empty function definition: function(){}
  • parameters have spaces after comma bla(b1, b2, b3);

  • when comma'd stuff needs to be broken up into multiple lines they are in front

    {
        bla: 'bla'
        , bla2: 'bla' 
    }
    
    or
    
    bla(blaaaaaaaaaaaaaaaaaaaaaaaaaaa
        , blaaaaaaaaaaaaaaaaa2)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment