Skip to content

Commit d303c6c

Browse files
author
hitsthings
committed
I thought the conditionals.html file was a bit misleading. The first form isn't an antipattern, IMO. Paul Irish explicitly said the latter forms were only superior for bookmarklets. So I ran a jsperf and linked it here so people can compare for themselves.
1 parent 144a0d0 commit d303c6c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

general-patterns/conditionals.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
</head>
77
<body>
88
<script>
9+
// NOTE: Paul Irish states that the first statement is only an antipattern when optimizing for
10+
// low-bandwidth source (such as for a bookmarklet.
11+
// Using the first statement will generally outperform the regex in a loop, and is faster than the
12+
// object literal for lower numbers of conditions (they generally even out around 10 conditions).
13+
// See http://jsperf.com/if-this-or-that
14+
915
// antipattern
1016
if (type === 'foo' || type === 'bar' ) {}
1117

0 commit comments

Comments
 (0)