javascript - Running private method out of an other method -
i initialize following code class readconfig:
var myreadconfig = new readconfig();
this works fine , alert("2") appears.
after run statement window.requestfilesystem(...) calls method gotfsreader. never see alert("3"); result.
how should run method gotfsreader out of window.requestfilesystem(...) ? if run outside of class works completely...
my class:
var readconfig = function(){ var path = "zugangsdaten.txt"; window.requestfilesystem(localfilesystem.persistent, 0, gotfsreader, failreader); alert("2"); var gotfsreader = function(filesystem) { alert("3"); filesystem.root.getfile(path, null, gotfileentryreader, failreader); } var gotfileentryreader = function(fileentry) { fileentry.file(gotfilereader, failreader); alert("4"); } var gotfilereader = function(file){ readastext(file); } var readastext = function(file) { var reader = new filereader(); reader.onloadend = function(evt) { console.log("read text"); handlelocalpasswort(evt.target.result); }; reader.readastext(file); } var failreader = function(evt) { console.log(evt.target.error.code); } var handlelocalpasswort = function(filestr){ if(filestr=="" || filestr == null){ return; } var arrayitems = filestr.split(";"); document.getelementbyid('tb_benutzer').value = arrayitems[0]; document.getelementbyid('tb_password').value = arrayitems[1]; document.getelementbyid('tb_knr').value = arrayitems[2]; checklogin(); } }
your code structured incorrectly. you're not initializing variable ("gotfsreader") until after pass value function. therefore, you're passing undefined, , not reference function.
move window.requestfilesystem() call after initialization, or declare functions function declaration statements:
function gotfsreader(filesystem) { alert("3"); filesystem.root.getfile(path, null, gotfileentryreader, failreader); } if that, it'll work, because function declaration statements treated if occur @ beginning of containing function.
variable declarations hoisted, there's difference: actual declaration part of var statement treated if occurs @ start of function. initialization done @ point in function var appears. thus, in code, variable called "gotfsreader" declared @ point call requestfilesystem(), it's not yet initialized.
Comments
Post a Comment