当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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 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: http://stackoverflow.com/a/8249333/640584

分享给朋友:
您可能感兴趣的文章:
随机阅读: