Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the value of Float32Array.length always 3?

I was reading the Mozilla Developer Network docs on Float32Arrays when I came upon

Float32Array.length
Length property whose value is 3.

... why is always 3? I also noticed that prototype property of the same name overrides it.

like image 524
John Hoffman Avatar asked Apr 05 '15 11:04

John Hoffman


People also ask

What is Float32Array?

The Float32Array typed array represents an array of 32-bit floating point numbers (corresponding to the C float data type) in the platform byte order. If control over byte order is needed, use DataView instead. The contents are initialized to 0 .


1 Answers

Float32Array is actually a function. You can check that like this

console.assert(typeof Float32Array === 'function');

And that function accepts three parameters. Quoting the signature from the same documentation,

Float32Array(buffer [, byteOffset [, length]]);

Quoting the Function.length documentation,

length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters.

That is why the length property of Float32Array is always 3.

like image 171
thefourtheye Avatar answered Sep 23 '22 05:09

thefourtheye