简体   繁体   中英

Javascript calling function out of order

In the code below, if I put a breakpoint on the call to storeCredentialsToSessionStorage() as well as a breakpoint on the definition of storeCredentialsToSessionStorage , when I get to the call and 'F10' it goes right to utils.navigate() and then later does the storeCredentialsToSessionStorage (ie, it skips the call and comes back to it) -- any ideas what I'm doing wrong here?

var login = function(canLogin, username, password) {
    if (canLogin == false) {
        utils.showError('Incorrect username or password');
        return;
    }

    storeCredentialsToSessionStorage(username, password);

    utils.navigate('#home-view');
}

var storeCredentialsToSessionStorage = function(username, password) {
    if (!Modernizr.sessionstorage) {
        utils.showError('There was an error accessing LocalStorage on this device.');
        return;
    }

    sessionStorage["username"] = username;
    sessionStorage["password"] = password;
}

As far as I know, hitting f10 doesn't make you jump INTO calls, you just jump to the next. Try F11 for that. (Assuming you use chrome for javascript debugging) Also try putting the breakpoints inside, not on the definition itself. By the way, you are just showing the definition of variables that store functions, maybe you are doing other calls in your code? Cannot know with what I'm seeing.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM