我有簡單的js腳本:setTimeout的作品更多的,我希望
const printDate = (interval) => {
setTimeout(() => {
console.log(new Date());
printDate();
}, interval);
};
printDate(1000);
而且我希望看到在控制檯1個記錄每1其次是因爲我已經通過了1000作爲間隔(即1秒)。
但是當我運行該腳本,我收到這樣的事情:
km:gh kvol$ node test.js
2017-07-20T05:54:20.241Z
2017-07-20T05:54:20.244Z
2017-07-20T05:54:20.246Z
2017-07-20T05:54:20.247Z
2017-07-20T05:54:20.249Z
2017-07-20T05:54:20.250Z
2017-07-20T05:54:20.252Z
2017-07-20T05:54:20.253Z
2017-07-20T05:54:20.255Z
2017-07-20T05:54:20.256Z
2017-07-20T05:54:20.258Z
2017-07-20T05:54:20.259Z
2017-07-20T05:54:20.261Z
2017-07-20T05:54:20.262Z
2017-07-20T05:54:20.264Z
2017-07-20T05:54:20.265Z
2017-07-20T05:54:20.267Z
2017-07-20T05:54:20.268Z
2017-07-20T05:54:20.270Z
2017-07-20T05:54:20.271Z
2017-07-20T05:54:20.273Z
2017-07-20T05:54:20.274Z
2017-07-20T05:54:20.276Z
2017-07-20T05:54:20.277Z
2017-07-20T05:54:20.279Z
2017-07-20T05:54:20.280Z
2017-07-20T05:54:20.281Z
2017-07-20T05:54:20.283Z
2017-07-20T05:54:20.284Z
2017-07-20T05:54:20.286Z
2017-07-20T05:54:20.288Z
2017-07-20T05:54:20.290Z
2017-07-20T05:54:20.291Z
2017-07-20T05:54:20.293Z
2017-07-20T05:54:20.294Z
2017-07-20T05:54:20.296Z
OMG!我很愚蠢......謝謝@FelixKling –