code:
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
What I don't understand is how does fileSystem get passed when there are no arguments passed with gotFS in the requestFileSystem?
The call to requestFileSystem is receiving the function gotFS as a parameter. gotFS isn't being invoked, a reference to the function is getting passed in. If gotFS was being evaluated you would see parens after it. (Also, parameters are not verified in Javascript, so you can call a function with less or more arguments than expected.)
gotFS
is passed as a variable (a callback). When requestFileSystem
is ready to, it calls gotFS
and passes the parameter.
Take this example:
function A(callback){
callback('hello world');
}
function B(test){
alert(test);
}
A(B);
A
is passed B
. A
then calls B
, passing 'hello world'
to it.
you have passed a function pointer to
window.requestFileSystem
in that method they can invoke and pass in any object they like
ie (psuedocode)
function window.requestFileSystem(localFs, someInt, functionDelegateToCallWithFS, fail)
{
//blah
var theFileSystemObject = fromSomwhereElse.get();
functionDelegateToCallWithFS(theFileSystemObject);
//blah
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.