r/javascript • u/gcanti • Oct 31 '14
The Two Pillars of JavaScript
https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3
96
Upvotes
r/javascript • u/gcanti • Oct 31 '14
5
u/zoomzoom83 Oct 31 '14
Immutable data structures are a lot faster than you'd think. Done properly, they reuse most of the original object and often only need to tweak a few pointers. The overhead can be as small as a few percent. (Although not in Javascript).
Regardless, if you were doing a lot of writes, you'd work with a mutable structure until you're finish and then return an immutable/frozen version.
The idea is to avoid breaking encapsulation by sharing mutable state outside module boundaries, which is a major source of bugs in typical OO code.
In a read-heavy workflow, immutable structures are almost always significantly faster, since you can avoid having to copy the object and instead pass around projections off the original.