11<!doctype html>
22< 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+ */
1212
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+ */
1919
20- function func ( ) {
21- var a = 1
22- , b = 2
23- , sum = a + b
24- , myobject = { }
25- , i
26- , j ;
27-
28- // function body...
29- }
20+ function func ( ) {
21+ var a = 1
22+ , b = 2
23+ , sum = a + b
24+ , myobject = { }
25+ , i
26+ , j ;
3027
31- function updateElement ( ) {
32- var el = document . getElementById ( "result" )
33- , style = el . style ;
34- // do something with el and style...
35- }
28+ // function body...
29+ }
3630
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
31+ function updateElement ( ) {
32+ var el = document . getElementById ( "result" )
33+ , style = el . style ;
34+ // do something with el and style...
35+ }
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
4242, b = 2
4343, sum = a + b
4444, myobject = { }
4545, i
4646, j ;
4747
48- // function body...
49- }
48+ // function body...
49+ }
5050
51- // References
52- // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
53- </ script >
54- </ body >
55- </ html >
51+ // References
52+ // http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
53+ </ script >
54+ </ body >
55+ </ html >
0 commit comments