我目前正在编写一个 API 来将文件解压缩到 Web 浏览器沙箱文件系统。我有一个基本的需要将参数传递给一个函数,而该函数本身又作为参数传递。下面是一些代码来说明这个问题:
//Request a permanent filesystem quota to unzip the catalog.
function requestFilesystem(size){
window.webkitStorageInfo.requestQuota(PERSISTENT, size*1024*1024, function(grantedBytes) {
window.requestFileSystem(PERSISTENT, grantedBytes, function(fs) {
filesystem = fs;
removeRecursively(filesystem.root, unzip(url), onerror);
}, onerror);
}, function(e) {
console.log('Error', e);
});
}
//unzip method can be changed, API remains the same.
//URL of zip file
//callback oncomplete
function unzip(URL) {
importZipToFilesystem(URL, function(){
console.log("Importing Zip - Complete!");
});
}
//remove removeRecursively a folder from the FS
function removeRecursively(entry, onend, onerror) {
var rootReader = entry.createReader();
console.log("Remove Recursive"+entry.fullPath);
rootReader.readEntries(function(entries) {
var i = 0;
function next() {
i++;
removeNextEntry();
}
function removeNextEntry() {
var entry = entries[i];
if (entry) {
if (entry.isDirectory)
removeRecursively(entry, next, onerror);
if (entry.isFile)
entry.remove(next, onerror);
} else
onend();
**Uncaught TypeError: undefined is not a function**
}
removeNextEntry();
}, onerror);
}
如果我尝试使用
function removeRecursively(entry, onend(URL), onerror) {
有一个错误,我的问题是如何传递解压缩函数的 URL 值,这个解压缩函数用作 removeRecursively 成功时的回调函数