简体   繁体   中英

Google Chrome console.log cached?

Sometimes when I'm using objects inside an userscript and using the TamperMonkey extension to run it, chrome's console.log() function is cached.
The code that effect it is this. The two console.log(save); always prints the same, although the will be the same. 相同。 However if I change console.log(save[testID]['lastCheck']); it will print differently.

function parseTestOverview(DOM)
{
    console.log(save);
    save[testID]['lastCheck'] = Date.now();
    var attempts = DOM.getElementsByClassName('answered');
    if(attempts.length == 0)
    {
        save[testID]['attempts'] = undefined;
        save[testID]['lastAttempt'] = undefined;
        save[testID]['lastAttempts'] = undefined;
        save[testID]['updated'] = false;
    }
    else if(save['lastAttempts'] || save['lastAttempts'] < attempts.length)
    {
        save[testID]['attempts'] = parseAttempts(attempts);
        var dateString = attempts[attempts.length - 1].innerText
            var dateTime = dateString.split(' ');
        var date = dateTime[0].split('-');
        var time = dateTime[1].split(':');
        save[testID]['lastAttempt'] = (new Date(date[2], date[1] - 1, date[0], time[0], time[1])).getTime();
        save[testID]['lastAttempts'] = attempts.length;
        save[testID]['updated'] = false;
    }
    else
    {
        save[testID]['updated'] = true;
    }
    GM_setValue('save', save);
    console.log(save);
    return attempts;
}

This may not make any out of context so here is the whole script: http://pastebin.com/u1qqCrt2

This may not make any sense either, because it is a site-specific script.

I'm running 15.0.859.0 canary on Mac OS X 10.7.1

This is because webkit only shows the value of the object when it is expanded in the console, not when it is printed.

See also: https://stackoverflow.com/a/8249333/640584

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