So far, there seem to be two opposing immutability solutions in Javascript:
immutable.js introduces its (shallow) immutable objects, which are incompatible with standard javascript protocols for objects and arrays.
seamlessly immutable uses POJOs that are completely immutable without magic but without structural separation.
It would be great to combine the best of both worlds. Can the correct prototype chain / tree decisions be immutable?
The basic prototype mechanism gives hope:
var a = [1, 2, 3];
var b = Object.create(a);
b[0];
b.map(function (x) { return ++x; });
b.push(4, 5, 6);
a;
b;
for (var i = 0; i < b.length; i++) {
console.log(b[i]);
}
a[1] = null;
a;
b;
b.unshift(0);
a;
b;
, (unshift) (b) , js, , . , .
, /, :
var a = [1, 2, 3];
Object.freeze(a);
var b = Object.create(a);
b.push(4, 5, 6);
Object.freeze(b);
: length , , . :
var b = Object.create(a, {length: {value: a.length, writable: true}});
, , , .
, - , .
Aadit , , .