I've a typed array (a 4-element Uint8ClampedArray, used for colors) that I would like to add a few properties to, object-like. One, for example, will be a Uint32 view to quickly get the pixel value. Optionally an other pair would be a map/index pair for where the color is in a colormap.
It's possible, i.e. no error and works correctly, but will it cause performance problems, or some other undesired side effect?
I won't be iterating over it, just accessing via color[n], n in 0-3, so that won't be an issue, and accessing properties by their names.
I ask because Typed Arrays were added as a highly performant, device independent, interchange .. like between the cpu and the gpu, and I'd like to not screw that up.
A simple performance test does not appear to show any kind of meaningful difference when accessing elements of the array if the array has custom properties.
See the test results here:
http://jsperf.com/uint8clampedarray-with-custom-properties
Or, run the test yourself using the following code:
Preparation Code
Control
Custom Properties Test
Results