3 ms·
Still doesn't give you immutable data structures though. For example: const myArray = [42]; myArray.push("Oh noes"); [42, "Oh noes"]
by AlexanderDhoore 13y ago
Still 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)