I have an object with a TypedArray member that I would like to freeze to prevent data from changing after it is installed. Trying to freeze TypedArray or ArrayBuffer did not behave as I expected. I would like to know, just out of curiosity, why he behaves the way he is. I run node 4.4.4 and Chrome, and it behaves more or less.
var typedArray = new Uint32Array(4); typedArray[0] = 10; typedArray[1] = 20; Object.freeze(typedArray);
The next thing I tried is to freeze the base ArrayBuffer
Object.freeze(typedArray.buffer); // Does not throws errors Object.isFrozen(typedArray.buffer); // returns true typedArray[0] = 50; // Successfully modifies the data, despite the buffer is frozen
I know that I can change my design so as not to save the original buffer and restore it from data elements when I need it. But I'm just curious about this behavior.
thanks
source share