forked from chuanxshi/javascript-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.html
More file actions
42 lines (36 loc) · 688 Bytes
/
globals.html
File metadata and controls
42 lines (36 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: Minimizing Globals
Description: create and access a global variable in a browser environment
*/
function sum(x, y) {
// antipatten: implied global
result = x + y;
return result;
}
function sum(x, y) {
var result = x + y;
return result;
}
// antipattern, do not use
function foo () {
var a = b = 0;
// ...
}
var a = (b = 0);
function foo() {
var a, b;
// ...
a = b = 0; // both local
}
// reference
// http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
</script>
</body>
</html>