java-script:immutability
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| java-script:immutability [2023/08/11 09:08] – [2. Object.freeze] odefta | java-script:immutability [2023/08/11 09:17] (current) – [3. Immutable.js] odefta | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| Object.freeze(obj); | Object.freeze(obj); | ||
| obj.x = 10; // Will have no effect </ | obj.x = 10; // Will have no effect </ | ||
| - | < | + | < |
| - | + | ||
| - | In **strict mode**, **obj.x = 10;** will throw a **TypeError**. | + | |
| - | In non-strict mode, the error is ignored. | + | |
| + | In **strict mode**, **obj.x = 10;** will throw a **TypeError**. In non-strict mode, the error is ignored. | ||
| </ | </ | ||
| Line 25: | Line 23: | ||
| Libraries such as Immutable.js provide persistent immutable data structures. These are collections that, once created, are never changed. Any modifications to the collection return a new collection that shares as much of the structure with the original as possible, minimizing unnecessary copying. | Libraries such as Immutable.js provide persistent immutable data structures. These are collections that, once created, are never changed. Any modifications to the collection return a new collection that shares as much of the structure with the original as possible, minimizing unnecessary copying. | ||
| + | |||
| + | < | ||
| + | |||
| + | < | ||
| + | **Object.freeze** can be slow, especially if used recursively on large objects. **Immutable.js** is optimized for performance and can handle large data structures efficiently. | ||
| + | </ | ||
| ===== 4. Functional Programming Techniques ===== | ===== 4. Functional Programming Techniques ===== | ||
java-script/immutability.1691744882.txt.gz · Last modified: 2023/08/11 09:08 by odefta
