Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

Just trying to wrap my head around 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.

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

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

why??

like image 644
user81993 Avatar asked Feb 03 '26 20:02

user81993


1 Answers

Not every input can be concatenated by + sign. For example you may want to concatenate 2 blobs:

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.

like image 169
Beniamin H Avatar answered Feb 05 '26 09:02

Beniamin H