Skip to content

Commit 64c810c

Browse files
committed
added conditionals
1 parent 58d925f commit 64c810c

File tree

3 files changed

+22
-66
lines changed

3 files changed

+22
-66
lines changed

function-patterns/function-application.html

Lines changed: 0 additions & 35 deletions
This file was deleted.

function-patterns/partial-application.html

Lines changed: 0 additions & 31 deletions
This file was deleted.

general-patterns/conditionals.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
// antipattern
10+
if (type === 'foo' || type === 'bar' ) {}
11+
12+
// preferred method 1 - regex test
13+
if ( /^(foo|bar)$/.test(type) ) {}
14+
15+
// preferred method 2 - object literal lookup (smaller if < 5 items)
16+
if ( ({foo:1,bar:1})[type] ) {}
17+
18+
// reference
19+
// http://paulirish.com/2009/perf/
20+
</script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)