javascript - 为什么 TypedArrays 有一个值为 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');
推荐阅读
- flutter - 我该如何解决这个弱警告?“该字段不会覆盖继承的 getter 或 setter。”
- python - 元组索引必须是整数或切片,而不是元组
- javascript - Puppeteer 文件路径太长
- java - 如何查找 Maven 插件目标的依赖项
- serial-port - 如何从串行端口接收到的字节中删除特定位数
- html - 我缺少什么让这个 div 居中作为电子邮件模板
- amazon-web-services - 雅典娜查询:写入位置时访问被拒绝:s3
- python - 如果我卸载 python 那么它也会卸载下载的包吗?
- php - WordPress PHP:如何为每个页面应用不同的 CSS 样式?
- c++ - 将列表映射到不同的类型