[英]I want to ask the meaning of the following code
Who can tell me the meaning of the following code? 谁能告诉我以下代码的含义?
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
type : contentType
});
This code creates a new Blob, with the following input parameters: 该代码使用以下输入参数创建一个新的Blob:
I'm guessing it's this part 我猜这就是这部分
appendABViewSupported ? array : array.buffer
that you are wondering about here. 您想知道这里。 It means: If "appendABViewSupported" is true , then use the "array" variable. 这意味着:如果“ appendABViewSupported”为true ,则使用“ array”变量。 Else, use the "array.buffer" variable. 否则,使用“ array.buffer”变量。
This code snippet does the same thing: 此代码段执行相同的操作:
var arrayOrArrayBuffer;
if (appendABViewSupported)
// If the "appendABViewSupported" variable is true, use the "array" variable
arrayOrArrayBuffer = array;
else
// Else, use the "array.buffer" variable
arrayOrArrayBuffer = array.buffer;
// Create the blob
blob = new Blob([ blob, arrayOrArrayBuffer ], { type : contentType });
But it's more elegant this way: 但是这样更优雅:
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], { type : contentType });
That code can be expanded like this (I think): 该代码可以这样扩展(我认为):
var a;
var b;
var c;
var blob;
if (appendABViewSupported) {
a = array;
} else {
a = array.buffer;
}
b = [ blob, a ]; // this bit seems like an issue to me but
// but would need to see the Blob code.
c = { type : contentType };
blob = new Blob(b,c);
All they have done is compress everything to make it more complex to read (some would say). 他们所做的只是压缩所有内容,使其阅读起来更加复杂(有人会说)。 Personally, I would have expanded some and used some of the short hand. 就个人而言,我会扩大一些并使用一些简写。 For example, I would have used a ternary at the very least like so: 例如,我至少会像这样使用三元数:
var a = appendABViewSupported ? array : array.buffer;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.