为什么Float32Array.length的值总是3

Why is the value of Float32Array.length always 3?

本文关键字:Float32Array length 为什么      更新时间:2023-09-26

当我遇到时,我正在阅读Float32Arrays上的Mozilla开发者网络文档

Float32Array.length
Length property whose value is 3.

为什么总是3?我还注意到,同名的prototype属性覆盖了它。

Float32Array实际上是一个函数。你可以像这个一样检查

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

这个函数接受三个参数。引用同一文件的签名,

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

引用Function.length文件,

length是函数对象的一个属性,表示函数需要多少个参数,即形式参数的数量。

这就是为什么CCD_ 5的CCD_。

这是因为构造函数最多需要3个参数:

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

JavaScript中的每个函数都有一个length属性,该属性将返回它所使用的命名参数的计数。

例如

function foo(a, b) {}
foo.length === 2; // true
function bar() {}
bar.length === 0; // true

这是(object-)函数Float32Array的参数数的长度。

然而,当您实例化它时,length将表示索引的数量:

console.log(Float32Array.length);  // => 3, number of arguments
var a = new Float32Array(10);      // create an instance with 10 indexes
console.log(a.length);             // => 10, number of indexes