Skip to content

Commit 956c04d

Browse files
committed
Merge pull request joomla#62 from CristinaSolana/gh-pages
Add content anchors and fix some oversights
2 parents 4263bdb + f19e34d commit 956c04d

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

manual/en-US/coding-standards/chapters/javascript.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
1+
## JavaScript
2+
3+
### Contents
4+
5+
1. [Naming Conventions](#naming-conventions)
6+
- [Variables](#naming-conventions-variables)
7+
- [Functions](#naming-conventions-functions)
8+
- [Reserved Words](#naming-conventions-reserved)
9+
2. [Syntax Style](#syntax-style)
10+
- [Indentation](#syntax-indentation)
11+
- [Spacing](#syntax-spacing)
12+
- [Commas](#syntax-commas)
13+
- [Semicolons](#syntax-semicolons)
14+
- [Quotes](#syntax-quotes)
15+
3. [Types](#types)
16+
4. [Functions](#functions)
17+
5. [Conditional Statements](#conditional-statements)
18+
6. [Blocks & Multi-line Statements](#blocks)
19+
7. [Comments](#comments)
20+
21+
<a name="naming-conventions"></a>
122
## Naming Conventions
223

324
Use descriptive words or terse phrases for names.
425

526
Variables and Functions should be camel case, starting with a lowercase letter: `likeThis`
627

7-
### Strings
28+
<a name="naming-conventions-variables"></a>
29+
### Variables
830

9-
**Use names that describe what the string is:**
31+
**Use names that describe what the variable is:**
1032

1133
`var element = document.getElementById('elementId');`
1234

1335
**Iterators are the exception**
1436

1537
Use i for index in a loop (and subsequent letters when necessary for nested iteration).
1638

39+
<a name="naming-conventions-functions"></a>
1740
### Functions
1841

1942
**Use names that describe what the function does:**
@@ -23,20 +46,22 @@ function getSomeData() {
2346
// statements
2447
}
2548
```
26-
49+
<a name="naming-conventions-reserved"></a>
2750
### Reserved Words
2851

2952
Do not use reserved words for anything other than their intended use. The list of: [Reserved Words](http://es5.github.io/#x7.6.1)
3053

3154
---
3255

56+
<a name="syntax-style"></a>
3357
## Syntax Style
3458

59+
<a name="syntax-indentation"></a>
3560
### Indentation
3661
- Don't mix tabs and spaces.
3762
- Tabs, 4 spaces
3863

39-
64+
<a name="syntax-spacing"></a>
4065
### Spacing
4166
- No whitespace at the end of line or on blank lines.
4267
- Unary special-character operators (e.g., !, ++) must not have space next to their operand.
@@ -117,7 +142,7 @@ foo( data, function() {
117142
});
118143
```
119144

120-
145+
<a name="syntax-commas"></a>
121146
### Commas
122147

123148
**Place commas after:**
@@ -141,7 +166,7 @@ array = [ 'foo', 'bar', ];
141166
array = [ 'foo', 'bar' ];
142167
```
143168

144-
169+
<a name="syntax-semicolons"></a>
145170
### Semicolons
146171

147172
Use them where expected.
@@ -164,14 +189,15 @@ function foo() {
164189
}
165190
```
166191

192+
<a name="syntax-quotes"></a>
167193
### Quotes
168194

169195
Use ' instead of "
170196

171197

172198
---
173199

174-
200+
<a name="variables"></a>
175201
## Variables
176202

177203
### Avoid Global Variables
@@ -216,6 +242,7 @@ var foo = 'bar',
216242
baz = 'qux';
217243
```
218244

245+
<a name="types"></a>
219246
## Types
220247

221248
### String
@@ -233,10 +260,6 @@ var longString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' +
233260
'cursus mauris.';
234261
```
235262

236-
```
237-
var foo = 'bar';
238-
```
239-
240263
### Number
241264

242265
Use `parseInt()` or `parseFloat()` instead of unary plus, for readability.
@@ -319,6 +342,7 @@ var myArr = [];
319342
myArr.push('foo');
320343
```
321344

345+
<a name="functions"></a>
322346
## Functions
323347

324348
### Chaining Method Calls
@@ -330,6 +354,7 @@ $('.someElement')
330354
.fadeIn();
331355
```
332356

357+
<a name="conditional-statements"></a>
333358
## Conditional Statements
334359

335360
Use ternary syntax if:
@@ -389,7 +414,7 @@ Use strict equality operator === so that type is considered in comparison. Using
389414
1 === "1"
390415
```
391416

392-
417+
<a name="blocks"></a>
393418
## Blocks & Multi-line Statements
394419

395420
Use curly braces on blocks that have more than one statement.
@@ -409,7 +434,7 @@ if ( test ) {
409434
}
410435
```
411436

412-
437+
<a name="comments"></a>
413438
## Comments
414439

415440
**Single Line**

0 commit comments

Comments
 (0)