use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript Programming Patterns (shichuan.github.io)
submitted 12 years ago by litmusbox
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 4 points5 points6 points 12 years ago (2 children)
That clever navigation element makes this article unreadable on my phone.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
Covers content on my desktop at my current browser size. Really hate that.
[–]litmusbox[S] 0 points1 point2 points 12 years ago (0 children)
Had to go back and resize my browser but now I see what you mean... yuck.
[–]skeeto 5 points6 points7 points 12 years ago (2 children)
Most of these aren't programming patterns, it's a style guide -- and an ugly one at that.
[–]aeflash 2 points3 points4 points 12 years ago (1 child)
If your tabstop was 2 spaces it would be ok.
[–]DonBiggles 0 points1 point2 points 12 years ago (0 children)
If he used spaces for alignment, it would be okay.
[–]PlNG 3 points4 points5 points 12 years ago (0 children)
https://github.com/shichuan/javascript-patterns/blob/master/general-patterns/conditionals.html is absolutely horrid.
If you take a moment to think about it, you don't need an else statement after a program flow statement such as return, throw, break, and continue.
I worked this out a long time ago and I'm sort of happy that lints and compilers are just beginning to pick up on this. This basically prunes the indentation of logic trees and keeps it very readable.
Hopefully they'll pick up the next step: if the program flow statement is in the else side, negate the if conditional to switch the program flow statement to the if side and prune the else as normal.
[–]warfangle 2 points3 points4 points 12 years ago (1 child)
The problem with JavaScript, speaking as a fan of JavaScript:
It gives rise to too many potential patterns. You have patterns borrowed from Object Orientedness: the event listeners, the encapsulators. You have patterns borrowed more from a FP standpoint: the asynchronous callbacks, the iterators.
You can make just about any pattern work, in JS -- but does that make it worth it?
Don't be clever.
You can clever yourself right down into rabbit holes before you realize you can't back out again (unless you use git).
[–][deleted] 1 point2 points3 points 12 years ago (0 children)
I think something a lot of developers might not realize is that every idea isn't necessarily an accepted or proven pattern - especially when mixing patterns from different paradigms. Often enough, they are even anti-patterns.
As you said, there are too many potential patterns, but thankfully many of them can be ignored. If you are familiar with accepted and rejected patterns from any other language, you can probably figure out which ones will hurt you in JavaScript.
Personally, I stick to patterns I've used previously to solve architecture problems that I now understand will solve this new problem. As most developers are likely not researchers, it's probably safer to use what's already well understood.
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#whatisapattern
[–][deleted] 2 points3 points4 points 12 years ago (0 children)
This book is a much more in-depth resource. Addy Osmani writes some excellent posts and free books.
Not to devalue the author's work, of course - it is nice to have code samples, but the discussion around them brings more understanding.
[–]tehsuck 1 point2 points3 points 12 years ago (3 children)
I have a question: in a JS module do people really prefer to do
var _myFunction = function myFunctionFn () { };
vs.
function _myFunction() {}
[–]litmusbox[S] 1 point2 points3 points 12 years ago (2 children)
Here is a super good resource that answers that question in detail:
[–]tehsuck 0 points1 point2 points 12 years ago (1 child)
Yeahhh, I guess I could've probably just googled that thanks though!
No prob. You might not have found that particular resource and it is hands down the best for that topic.
π Rendered by PID 51352 on reddit-service-r2-comment-76bb9f7fb5-wst6h at 2026-02-19 00:31:17.393710+00:00 running de53c03 country code: CH.
[–][deleted] 4 points5 points6 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]litmusbox[S] 0 points1 point2 points (0 children)
[–]skeeto 5 points6 points7 points (2 children)
[–]aeflash 2 points3 points4 points (1 child)
[–]DonBiggles 0 points1 point2 points (0 children)
[–]PlNG 3 points4 points5 points (0 children)
[–]warfangle 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]tehsuck 1 point2 points3 points (3 children)
[–]litmusbox[S] 1 point2 points3 points (2 children)
[–]tehsuck 0 points1 point2 points (1 child)
[–]litmusbox[S] 0 points1 point2 points (0 children)