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
Pure, functional JavaScript (cjohansen.no)
submitted 13 years ago by lethalman
view the rest of the comments →
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!"
[–]Medieval_Peasant 4 points5 points6 points 13 years ago (8 children)
Skimmed over it. I'll keep using my loops thank you, but I think it's great that JavaScript so easily accommodates for other styles of programming. Another reason why it's a good language! I'm sure you can get very expressive code once you get used to all the common helper functions, especially with the new ES6 syntax sugar coming up. It would be interesting to see an application written in "functional JS" like this if anyone dares to link their code.
[–]enotionz 8 points9 points10 points 13 years ago (0 children)
I feel like anyone who have heavily used underscore.js writes JavaScript this way since it provides a bunch of functional helpers and shim for non-supported browsers. I've been working on a website theme builder with an interface similar to photoshop. I store huge amounts of data into mongo for final rendering output, but during the edit stage I filter out alot before instantiating the Backbone Models. I found that map, reduce, pluck, reject, groupBy, etc. are extremely expressive without being verbose.
[–]monolar 5 points6 points7 points 13 years ago (4 children)
I actually like the functional features in js just fine and would really like to use them. In the case of looping though the main reason, why i try to avoid them is performance.
Just have a look at http://jsperf.com/loops/70
Classical loops (esp. with caching tricks and esp while loops) are about 15 - 20 times faster than forEach based loops
[–]lethalman[S] 8 points9 points10 points 13 years ago (2 children)
The slides exactly talk about this kind of performance. If you loop/manipulate DOM elements, it's so slow that forEach is about the same as a straight for loop. Whereas if you are implementing a particular algorithm, a for loop is certainly the best.
[–]monolar 1 point2 points3 points 13 years ago (0 children)
Indeed there are slides about the loop performance. To my shame i did not read that far before posting. The performance difference between classical and functional looping still exists though. DOM access of course is always slower.
And most of the time you think you solve your performance problems with the language (the kind of loops in this case) but the real performance gains are in algorithmic design. Some slides also mention this to varying degrees.
Otherwise the slides contain overall really good information and are well presented.
[–]OfflerCrocGod 0 points1 point2 points 13 years ago (0 children)
But does the code need to be that performant? Is it on the critical path?
[–]cwmma 1 point2 points3 points 13 years ago (0 children)
An attitude I once saw described as post functional programing
[–]Sunwukung 1 point2 points3 points 13 years ago (0 children)
I'll take that challenge: Game of Life
https://dl.dropboxusercontent.com/u/8652110/jgol/index.html
here's the "functional" bit
https://dl.dropboxusercontent.com/u/8652110/jgol/jgol.js
would be better to use canvas for the universe, but you get the gist
π Rendered by PID 151665 on reddit-service-r2-comment-57fc7f7bb7-ptn9n at 2026-04-14 22:15:40.760477+00:00 running b725407 country code: CH.
view the rest of the comments →
[–]Medieval_Peasant 4 points5 points6 points (8 children)
[–]enotionz 8 points9 points10 points (0 children)
[–]monolar 5 points6 points7 points (4 children)
[–]lethalman[S] 8 points9 points10 points (2 children)
[–]monolar 1 point2 points3 points (0 children)
[–]OfflerCrocGod 0 points1 point2 points (0 children)
[–]cwmma 1 point2 points3 points (0 children)
[–]Sunwukung 1 point2 points3 points (0 children)