3 ms·
You could use const all over the place.
by MatthewPhillips 13y ago
You could use const all over the place.
- AlexanderDhoore 13y agoStill doesn't give you immutable data structures though. For example: const myArray = [42]; myArray.push("Oh noes"); [42, "Oh noes"]
- MatthewPhillips 13y agoUgh, you're kidding? EDIT: checked in Node, yep. That's unfortunate. Can we get a let foo immutable = [1]; or something? EDIT2: Although this can be implemented in user-land with Object.freeze. Create a function that returns a const that is frozen if it is non-primitive. That should cover it, right?
- kevingadd 13y agofreeze/seal don't actually provide true immutability in JS. There are cases where a frozen object can still be modified (Date is one of them, IIRC typed arrays are another)
- tensor 13y agoClojureScript provides truly immutable data structures that compile down to javascript. You can use them from JS: https://github.com/swannodette/mori https://github.com/swannodette/mori