Typed arrays in JavaScript
NERD ALERT! The Firefox 4 beta features typed arrays in JavaScript. They have been introduced to improve performance when working with binary data e.g. in Mozilla’s implementation of the FileAPI. Currently raw data is parsed as a string and read character by character using charCodeAt(). Typed arrays let you work with raw binary data. As a side effect, a JavaScript typed array will only let you store one type of variable within it; you can not mix strings and floats. And a JavaScript typed array will not allow you to change the size of the array after instantiation. Here are the types you can specify:
Int8Array
Uint8Array
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
While the performance results (http://weblog.bocoup.com/javascript-typed-arrays) are undoubtedly impressive, is there a place for typing in JavaScript? Surely the flexibility, dynamic nature and lightweight syntax of the language is it’s appeal? Introducing typed arrays is cited as a performance improvement, but in fact many other areas of the language could be dramatically improved by changing or introducing new features, so are Mozilla setting a dangerous precedent here? The abandoned ECMAScript 4th edition (PDF link) featured optional type annotations as well as optional static type checking, but the most recently approved ECMAScript 5th edition (PDF link) has neither of these.
Interestingly, the typed array draft spec originally came out of the spec for WebGL, the 3D graphics context of the HTML5 Canvas element.
Your thoughts? Happy, sad? Tearful? OUTRAGED? Leave a comment below and let’s tell Mozilla exactly what we think of their spec-disregardin’.
Tags: interfacedevelopment, javascript, performance, syntax, typing



