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.
console.log(save);
always prints the same, although the will never 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
精彩评论