We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8f12c2b commit 4854900Copy full SHA for 4854900
1 file changed
general-patterns/function-declarations.html
@@ -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