From 849edf9c42f85e6251f8da9050d4a44c7a26fc3a Mon Sep 17 00:00:00 2001 From: Cristina Solana Date: Thu, 20 Feb 2014 22:30:54 -0500 Subject: [PATCH 1/3] Add heading, [fix] exchange 'string' for 'variable' --- manual/en-US/coding-standards/chapters/javascript.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manual/en-US/coding-standards/chapters/javascript.md b/manual/en-US/coding-standards/chapters/javascript.md index c6a09bf4..79300505 100644 --- a/manual/en-US/coding-standards/chapters/javascript.md +++ b/manual/en-US/coding-standards/chapters/javascript.md @@ -1,12 +1,14 @@ +## JavaScript + ## Naming Conventions Use descriptive words or terse phrases for names. Variables and Functions should be camel case, starting with a lowercase letter: `likeThis` -### Strings +### Variables -**Use names that describe what the string is:** +**Use names that describe what the variable is:** `var element = document.getElementById('elementId');` From 26d396e514e91a54c3355962f3b4ee75eaa037f4 Mon Sep 17 00:00:00 2001 From: Cristina Solana Date: Thu, 20 Feb 2014 22:38:23 -0500 Subject: [PATCH 2/3] remove stray example --- manual/en-US/coding-standards/chapters/javascript.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/manual/en-US/coding-standards/chapters/javascript.md b/manual/en-US/coding-standards/chapters/javascript.md index 79300505..36e38123 100644 --- a/manual/en-US/coding-standards/chapters/javascript.md +++ b/manual/en-US/coding-standards/chapters/javascript.md @@ -235,10 +235,6 @@ var longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' + 'cursus mauris.'; ``` -``` -var foo = 'bar'; -``` - ### Number Use `parseInt()` or `parseFloat()` instead of unary plus, for readability. From f19e34dec97e4c4aee8c5ee02ab9f1c32cb4b1c2 Mon Sep 17 00:00:00 2001 From: Cristina Solana Date: Thu, 20 Feb 2014 23:32:59 -0500 Subject: [PATCH 3/3] Add in doc TOC --- .../coding-standards/chapters/javascript.md | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/manual/en-US/coding-standards/chapters/javascript.md b/manual/en-US/coding-standards/chapters/javascript.md index 36e38123..b27fde09 100644 --- a/manual/en-US/coding-standards/chapters/javascript.md +++ b/manual/en-US/coding-standards/chapters/javascript.md @@ -1,11 +1,31 @@ ## JavaScript +### Contents + +1. [Naming Conventions](#naming-conventions) + - [Variables](#naming-conventions-variables) + - [Functions](#naming-conventions-functions) + - [Reserved Words](#naming-conventions-reserved) +2. [Syntax Style](#syntax-style) + - [Indentation](#syntax-indentation) + - [Spacing](#syntax-spacing) + - [Commas](#syntax-commas) + - [Semicolons](#syntax-semicolons) + - [Quotes](#syntax-quotes) +3. [Types](#types) +4. [Functions](#functions) +5. [Conditional Statements](#conditional-statements) +6. [Blocks & Multi-line Statements](#blocks) +7. [Comments](#comments) + + ## Naming Conventions Use descriptive words or terse phrases for names. Variables and Functions should be camel case, starting with a lowercase letter: `likeThis` + ### Variables **Use names that describe what the variable is:** @@ -16,6 +36,7 @@ Variables and Functions should be camel case, starting with a lowercase letter: Use i for index in a loop (and subsequent letters when necessary for nested iteration). + ### Functions **Use names that describe what the function does:** @@ -25,20 +46,22 @@ function getSomeData() { // statements } ``` - + ### Reserved Words Do not use reserved words for anything other than their intended use. The list of: [Reserved Words](http://es5.github.io/#x7.6.1) --- + ## Syntax Style + ### Indentation - Don't mix tabs and spaces. - Tabs, 4 spaces - + ### Spacing - No whitespace at the end of line or on blank lines. - Unary special-character operators (e.g., !, ++) must not have space next to their operand. @@ -119,7 +142,7 @@ foo( data, function() { }); ``` - + ### Commas **Place commas after:** @@ -143,7 +166,7 @@ array = [ 'foo', 'bar', ]; array = [ 'foo', 'bar' ]; ``` - + ### Semicolons Use them where expected. @@ -166,6 +189,7 @@ function foo() { } ``` + ### Quotes Use ' instead of " @@ -173,7 +197,7 @@ Use ' instead of " --- - + ## Variables ### Avoid Global Variables @@ -218,6 +242,7 @@ var foo = 'bar', baz = 'qux'; ``` + ## Types ### String @@ -317,6 +342,7 @@ var myArr = []; myArr.push('foo'); ``` + ## Functions ### Chaining Method Calls @@ -328,6 +354,7 @@ $('.someElement') .fadeIn(); ``` + ## Conditional Statements Use ternary syntax if: @@ -387,7 +414,7 @@ Use strict equality operator === so that type is considered in comparison. Using 1 === "1" ``` - + ## Blocks & Multi-line Statements Use curly braces on blocks that have more than one statement. @@ -407,7 +434,7 @@ if ( test ) { } ``` - + ## Comments **Single Line**