0
だから私はphantomjsのために次のことを使用しているためにJavaScriptでコールバック関数ではまだ未定義です:変数はPhantomJS
var time = 1490543999999999;
var endTime = time - 518400000000 * 10;
var mintime = time - 518399999999;
console.log("mintime after assignment is"+mintime);
var loopnumber = 6;
page.open('https://myactivity.google.com/item?min=' + mintime + '&max=' + time + '&product=5,6,7,10,11,12,13,15,19,20,25,27,28', callback);
function callback() {
console.log("inside callback and loopnumber is "+loopnumber+"and time is "+time+", and mintime is "+mintime+'. URL: https://myactivity.google.com/item?min=' + mintime + '&max=' + time + '&product=5,6,7,10,11,12,13,15,19,20,25,27,28');
page.render('/Users/jMac-NEW/Documents/FILEMAKER OCLC/login_test33.7_brkpoint' + loopnumber + '.png');
fs.write('/Users/jMac-NEW/Documents/FILEMAKER OCLC/login_test33.7_brkpoint' + loopnumber + 'html.html', page.content, 'w');
time -= 518400000000;
loopnumber++;
if (time > endTime) {
var mintime = time - 518399999999;
page.open('https://myactivity.google.com/item?min=' + mintime + '&max=' + time + '&product=5,6,7,10,11,12,13,15,19,20,25,27,28', callback);
}
else {
phantom.exit();
}
}
これは最初にconsole.logのために出力されます:
mintime after assignment is1490025600000000
しかし、コールバック()内のconsole.logについては、これは出力です。
inside callback and loopnumber is 6and time is 1490543999999999, and mintime is undefined. URL: https://myactivity.google.com/item?min=undefined&max=1490543999999999&product=5,6,7,10,11,12,13,15,19,20,25,27,28
なぜmintimeですか=未定義、他の変数(ループ番号と時間)がない場合は?
関数内の 'mintime'の2番目の宣言は、外側宣言をシャドウします。 – user5090812
@ user5090812なぜそれは未定義に終わるのですか? 2番目の宣言であっても、それはまだ数字です – humanitiesclinic