|
1 | 1 | <!doctype html> |
2 | 2 | <html lang="en"> |
3 | | - <head> |
4 | | - <title>JavaScript Patterns</title> |
5 | | - <meta charset="utf-8"> |
6 | | - </head> |
7 | | - <body> |
8 | | - <script> |
9 | | - /* Title: Single var Pattern |
10 | | - Description: use one var statement and declare multiple variables |
11 | | - */ |
| 3 | +<head> |
| 4 | + <title>JavaScript Patterns</title> |
| 5 | + <meta charset="utf-8"> |
| 6 | +</head> |
| 7 | + <body> |
| 8 | + <script> |
| 9 | + /* Title: Single var Pattern |
| 10 | + Description: use one var statement and declare multiple variables |
| 11 | + */ |
12 | 12 |
|
13 | | - /* Benefits: |
14 | | - * 1. Provides a single place to look for all the local variables needed by the function |
15 | | - * 2. Prevents logical errors when a variable is used before it's defined |
16 | | - * 3. Helps you remember to declare variables and therefore minimize globals |
17 | | - * 4. Is less code (to type and to transfer over the wire) |
18 | | - */ |
| 13 | + /* Benefits: |
| 14 | + * 1. Provides a single place to look for all the local variables needed by the function |
| 15 | + * 2. Prevents logical errors when a variable is used before it's defined |
| 16 | + * 3. Helps you remember to declare variables and therefore minimize globals |
| 17 | + * 4. Is less code (to type and to transfer over the wire) |
| 18 | + */ |
19 | 19 |
|
20 | | - function func() { |
21 | | - var a = 1 |
22 | | - , b = 2 |
23 | | - , sum = a + b |
24 | | - , myobject = {} |
25 | | - , i |
26 | | - , j; |
| 20 | + function func() { |
| 21 | + var a = 1 |
| 22 | + , b = 2 |
| 23 | + , sum = a + b |
| 24 | + , myobject = {} |
| 25 | + , i |
| 26 | + , j; |
27 | 27 |
|
28 | | - // function body... |
29 | | - } |
| 28 | + // function body... |
| 29 | + } |
30 | 30 |
|
31 | | - function updateElement() { |
32 | | - var el = document.getElementById("result") |
33 | | - , style = el.style; |
34 | | - // do something with el and style... |
35 | | - } |
| 31 | + function updateElement() { |
| 32 | + var el = document.getElementById("result") |
| 33 | + , style = el.style; |
| 34 | + // do something with el and style... |
| 35 | + } |
36 | 36 |
|
37 | | - // Preferred way |
38 | | - // Move commas BEFORE vars |
39 | | - // You'll not forget to add one when adding variable to the end of list |
40 | | - function func() { |
41 | | - var a = 1 |
42 | | - , b = 2 |
43 | | - , sum = a + b |
44 | | - , myobject = {} |
45 | | - , i |
46 | | - , j; |
| 37 | + // Preferred way |
| 38 | + // Move commas BEFORE vars |
| 39 | + // You'll not forget to add one when adding variable to the end of list |
| 40 | + function func() { |
| 41 | + var a = 1 |
| 42 | + , b = 2 |
| 43 | + , sum = a + b |
| 44 | + , myobject = {} |
| 45 | + , i |
| 46 | + , j; |
47 | 47 |
|
48 | | - // function body... |
49 | | - } |
| 48 | + // function body... |
| 49 | + } |
50 | 50 |
|
51 | | - // References |
52 | | - // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ |
53 | | - </script> |
54 | | - </body> |
| 51 | + // References |
| 52 | + // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/ |
| 53 | + </script> |
| 54 | + </body> |
55 | 55 | </html> |
0 commit comments