Skip to content

Commit 4854900

Browse files
committed
added function declarations pattern and antipattern
1 parent 8f12c2b commit 4854900

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>JavaScript Patterns</title>
5+
<meta charset="utf-8">
6+
</head>
7+
<body>
8+
<script>
9+
/* Title: Function Declarations
10+
Description: creating anonymous functions and assigning them to a variable
11+
*/
12+
13+
// antipattern
14+
function getData() {}
15+
16+
17+
// preferred
18+
var getData = function() { };
19+
20+
21+
/* Explanation:
22+
advantages of using the second pattern:
23+
1. Makes it easier to understand "functions as an object".
24+
2. It enforces good semicolon habits.
25+
3. Doesn't have much of the baggage traditionally associated with functions and scope.
26+
*/
27+
28+
// reference
29+
// http://ejohn.org/blog/javascript-as-a-first-language/
30+
</script>
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)