as you maybe know, that if you use a complex structure in JS it's passed as a reference.
varref = {something : 0};
console.log(ref);
function mutable(ref) {
ref['something'] = 1;
}
mutable(ref);
console.log(ref);
function breakReference(ref) {
var localRef = JSON.parse(JSON.stringify(ref));
localRef['something'] = 2;
}
console.log(ref);
this is one classic side-effect that happens in a lot of apps because developers don't understand that references are mutable.
this is just why you should care about it or at least you should know what it does.
Amn:
Immutability in this case means .... you pass any parameter and it stays the same on the outside despite changes on the inside and the other way around.
j
stuff ;)
as you maybe know, that if you use a complex structure in JS it's passed as a reference.
var ref = {something : 0}; console.log(ref); function mutable(ref) { ref['something'] = 1; } mutable(ref); console.log(ref); function breakReference(ref) { var localRef = JSON.parse(JSON.stringify(ref)); localRef['something'] = 2; } console.log(ref);this is one classic side-effect that happens in a lot of apps because developers don't understand that references are mutable.
this is just why you should care about it or at least you should know what it does.
Amn: Immutability in this case means .... you pass any parameter and it stays the same on the outside despite changes on the inside and the other way around.