【发布时间】:2016-11-16 22:43:35
【问题描述】:
谁能告诉我以下代码的含义?
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
type : contentType
});
【问题讨论】:
标签: javascript blob zip.js
谁能告诉我以下代码的含义?
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
type : contentType
});
【问题讨论】:
标签: javascript blob zip.js
此代码使用以下输入参数创建一个新 Blob:
我猜是这个部分
appendABViewSupported ? array : array.buffer
你想知道这里。这意味着:如果“appendABViewSupported”为true,则使用“array”变量。否则,使用“array.buffer”变量。
这段代码 sn-p 做同样的事情:
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 });
但这样更优雅:
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], { type : contentType });
【讨论】:
该代码可以像这样扩展(我认为):
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);
他们所做的只是压缩所有内容,使其更易于阅读(有人会说)。就个人而言,我会扩展一些并使用一些速记。例如,我至少会像这样使用三元:
var a = appendABViewSupported ? array : array.buffer;
【讨论】: