Skip to content

Commit

Permalink
resolved merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanxshi committed Jun 10, 2018
1 parent fa0f600 commit cf07086
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions general-patterns/single-var-pattern.html
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: Single var Pattern
Description: use one var statement and declare multiple variables
*/
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: Single var Pattern
Description: use one var statement and declare multiple variables
*/

/* Benefits:
* 1. Provides a single place to look for all the local variables needed by the function
* 2. Prevents logical errors when a variable is used before it's defined
* 3. Helps you remember to declare variables and therefore minimize globals
* 4. Is less code (to type and to transfer over the wire)
*/
/* Benefits:
* 1. Provides a single place to look for all the local variables needed by the function
* 2. Prevents logical errors when a variable is used before it's defined
* 3. Helps you remember to declare variables and therefore minimize globals
* 4. Is less code (to type and to transfer over the wire)
*/

function func() {
var a = 1
, b = 2
, sum = a + b
, myobject = {}
, i
, j;

// function body...
}
function func() {
var a = 1
, b = 2
, sum = a + b
, myobject = {}
, i
, j;

function updateElement() {
var el = document.getElementById("result")
, style = el.style;
// do something with el and style...
}
// function body...
}

// Preferred way
// Move commas BEFORE vars
// You'll not forget to add one when adding variable to the end of list
function func() {
var a = 1
function updateElement() {
var el = document.getElementById("result")
, style = el.style;
// do something with el and style...
}

// Preferred way
// Move commas BEFORE vars
// You'll not forget to add one when adding variable to the end of list
function func() {
var a = 1
, b = 2
, sum = a + b
, myobject = {}
, i
, j;

// function body...
}
// function body...
}

// References
// https://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
</script>
</body>
</html>
// References
// https://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
</script>
</body>
</html>

0 comments on commit cf07086

Please sign in to comment.