Immutable objects
sometimes you come across a situation where you need to copy a variable content of type object (Object, Array) into an other one and work with both copies in the same module or in the same document. When you try to immute the state of one variable the change is immediately incorporated into the other copy as javascript is also a language where objects are passed by reference. So here comes immutable objects to solve immutability issue and it's a good match when you have a complex object structure containing multiple objects and arrays.
Installation && usage
npm install --save immutable-js-objects
- then using commonJs or ES6 import statement
var immutableObjects= // or
Code Demo
// considering you have this objectvar object= name: 'cloud' age: 20 identity: number: 'NO123' city: 'Boston' adress: 'xxxxx123' hobbies: id: 0 label: 'hockey'id: 1 label: 'tennis'id: 2 label: 'football' // in the normal case you would do var object2= object // using immutable-objectsvar object2= // Now you will have a new Object whose objects references points at new values with new adresses in memory
Tests
npm test// Orgrunt test