Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

JavaScript is functional but not in a strict sense. It does not rely on immutable data and side-effect free functions. There are a few libs that provide immutable data structures, so I believe it should be possible to write a more strictly functional program using JavaScript.

I know ClojureScript exists but I am not interested in transcompilation.

Are there any open source projects that use JavaScript in a more strictly functional sense with nothing but immutable data? I am interested in whether this is practical in a language not built with this in mind.

share|improve this question

closed as off-topic by gnat, GlenH7, thorsten müller, MichaelT, Bart van Ingen Schenau Jan 21 at 11:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – gnat, thorsten müller, MichaelT, Bart van Ingen Schenau
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
It's tricky to rely fully on immutable data in javascript, the permissibility of the language makes optimizations for such paradigms difficult and thus performance becomes a big issue. This makes me skeptical that projects of any significant size/note use anything but "pragmatically" functional styles. TLDR Slooooowwwww –  jozefg Jan 19 at 5:01
1  
This question was closed as off-topic (for reasons that I fail to understand) so I can't post an answer. Take a look at the Mori project. It uses immutable data structures taken from ClojureScript but using plain JavaScript. It may be something that you're looking for. –  rsp May 27 at 1:18
    
youtube.com/watch?v=mS264h8KGwk Talk on immutability in JS. (It's not that slow) –  Sukima Jun 23 at 16:04
    
@Sukima -- saw the talk and Nolen shows us persistent data and FP is ready for the big time. –  Mario T. Lanza Jun 28 at 12:24
1  
Facebook has immutable.js out. Similar to mori, but smaller. Mori minified and gzipped 30k, immutable.js minified and gzipped 10k. They don't use plain objects so they can get higher performance. –  Jon49 Sep 27 at 8:16

1 Answer 1

I wanted to expand a bit on what jozefg commented on above.
He's probably right that it would be slow, because JS compilers don't have support for immutability.
If you look at Erlang (language with built-in immutability), the compiler knows about immutability, so it can optimize for it. For example, i'f I'm not mistaken, immutable objects are not all complete clones from each other, but are stored internally as pointers to the original object together with any data that's different from the original data.
If you're going to try immutability all over the place in JS, you're going to have a massive amount of objects, which all are going to have to be garbage collected at some point...

share|improve this answer
2  
I appreciate the feedback; however, ClojureScript runs on top of JavaScript and uses all the immutable/persistent data structures Clojure provides. Mori.js ports these to vanilla JavaScript. This seems to allude that doing the same thing in native JavaScript should not be much of a stretch, if only people would choose to follow a more functional paradigm. –  Mario T. Lanza Jan 19 at 21:04
    
While it's a good point, this isn't an answer. –  user39685 Jan 20 at 17:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.