简体   繁体   English

为什么 Blob 构造函数只将数组作为第一个参数?

[英]Why does Blob constructor only take an array as the first argument?

Just trying to wrap my head around Blob只是想把我的头绕在 Blob 上

Reading this: https://developer.mozilla.org/en-US/docs/Web/API/Blob gives no explanation as to why the first argument must be an array.阅读: https : //developer.mozilla.org/en-US/docs/Web/API/Blob没有解释为什么第一个参数必须是数组。

If I do supply multiple things in that array, it just stitches them together end to end which seems like a really odd feature to force on every blob creation如果我确实在该数组中提供了多个内容,它只会将它们首尾相连地缝合在一起,这似乎是一个非常奇怪的功能,可以强制创建每个 blob

New Blob(["a", "b"])
is the exact same as 
New Blob(["a" + "b"])

why??为什么??

Not every input can be concatenated by + sign.并非每个输入都可以用+号连接。 For example you may want to concatenate 2 blobs:例如,您可能想要连接 2 个 blob:

const blob = new Blob([new Blob(['a']), new Blob(['b'])])
// ab

It's not the same as:它不同于:

const blob = new Blob([new Blob(['a']) + new Blob(['b'])])
// [object Blob][object Blob]

Using an array as an input it's a bit more flexible as Blob implementation will take care of concatenation of the given input.使用数组作为输入更加灵活,因为 Blob 实现将处理给定输入的串联。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么javascript构造函数会打印传递给它的参数? - Why does javascript constructor prints the argument passed to it? 为什么我的javascript函数仅返回数组的第一项? - Why does my javascript function returns only first item of an array ? 为什么我的 for 循环只将第一个结果返回到 JavaScript 中的数组? - Why does my for loop only return the first result to an array in JavaScript? ReactDOM.render 的第一个参数是什么? - What does the first argument of ReactDOM.render take? 为什么“函数”的第一个参数拒绝括号? - Why does first argument of `Function` deny parentheses? 为什么在我已经打印了数组的所有值的情况下只返回数组的第一个元素? - Why does it only returns only the first element of the array while i've already printed all the values of the array? 只能从枚举数组中获取值的 JSDoc 文档参数 - JSDoc document argument that can only take a value from an enum array 作为(构造函数)function 的参数的扩展运算符是否总是会产生一个数组,如果是,为什么? - Will the spread operator as argument of a (constructor) function always result in an Array, and if so, why? 为什么第一个数据 READ 总是耗时最长? - Why does the first data READ always take the longest? 为什么玩家1总是会先走? - Why does player 1 always get to take the first turn?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM