Reputation: 11680
What is this syntax, and why does it work?
const content : string = functionThatReturnsAString();
const blob = new Blob([content]);
What is this [string]
?
What does it return, and for which Blob() constructor is it an acceptable argument?
Sorry for the simple question, but I'd managed to convince myself that something much more complicated must be going on. What with spread syntax, et al., theere are a lot of new overloads of [] and {} that I'm only beginning to get a grasp on, and I convinced myself this was one of them.
Upvotes: 1
Views: 72
Reputation: 4097
That's an array literal with one item, composed of content
. It's the same as
const content : string = functionThatReturnsAString();
const arr = [];
arr.push(content);
const blob = new Blob(arr);
or
const content : string = functionThatReturnsAString();
const arr = [content];
const blob = new Blob(arr);
The Blob constructor accepts as arguments:
new Blob(array, options);
so the string must be put into an array first.
Upvotes: 5