为什么 TypedArrays 的静态长度 属性 值为 3

Why do TypedArrays have a static length property with value 3

我刚刚在查找一些 Uint8Array 属性时遇到 this gem

TypedArray.length

    Length property whose value is 3.

我试过了,是真的!

什么?为什么会这样?!

对于函数,长度属性是它的参数列表中有多少个参数。对于 Uint8Array 构造函数,该数字为 3.

function example2 (a, b) {}
function example3 (a, b, c) {}

console.log(example2.length);
console.log(example3.length);

无论长度如何属性,任何函数都可以传递任意数量的参数,函数可以使用或忽略所有参数。所以长度只是关于可能使用多少的提示。

// This function doesn't list any arguments, so it's length is 0
function example () {
  // ...but it uses 2 anyway.
  console.log(arguments[0], arguments[1])
}
console.log(example.length);
// .. and i can pass in more than 2, useless though it is.
example('first', 'second', 'third');