JavaScript Typed Arrays pose a danger when it comes to endianness.
Suppose that you have a function like this:
var encodeFloat32 = (function() {
var arr = new Float32Array( 1 );
var char = new Uint8Array( arr.buffer );
return function( number ) {
arr[0] = number;
return String.fromCharCode( char[0], char[1], char[2], char[3] );
};
}());
This is a potentially dangerous function if you were to run it on a Big Endian system due to the order in which you submit the ArrayBuffers bytes to the "fromCharCode" method.
Therefore you would need to create some kind of endian safety in order to make your code platform-independent.
What is the best practice to create "endian safety" across an application written in JavaScript? Are there any workarounds?