【发布时间】:2020-03-30 13:46:18
【问题描述】:
【问题讨论】:
-
在控制台中运行:
var x = new Uint8Array([17, -45.3]); console.log(x.length); -
哈我知道有人会认为我在问如何获得正确的长度。这不是我要问的。
标签: javascript typed-arrays uint8array
【问题讨论】:
var x = new Uint8Array([17, -45.3]); console.log(x.length);
标签: javascript typed-arrays uint8array
对于函数,长度属性是其参数列表中有多少个参数。对于 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');
【讨论】: