Closed kira8565 closed 8 years ago
1、 var CronJob = require('cron').CronJob; for (var i = 0; i < 2; i++) { new CronJob('* * * * * *', consoleLog(i), null, true, 'America/Los_Angeles'); } function consoleLog(i) { console.log(i); }
when i run this code ,the job run only once and will not continute
2、 var CronJob = require('cron').CronJob; for (var i = 0; i < 2; i++) { new CronJob('* * * * * *', function () { console.log(i); }, null, true, 'America/Los_Angeles'); }
when i run the code above ,i get 2 2 rather than 0 1
1、 var CronJob = require('cron').CronJob; for (var i = 0; i < 2; i++) { new CronJob('* * * * * *', consoleLog(i), null, true, 'America/Los_Angeles'); } function consoleLog(i) { console.log(i); }
when i run this code ,the job run only once and will not continute
2、 var CronJob = require('cron').CronJob; for (var i = 0; i < 2; i++) { new CronJob('* * * * * *', function () { console.log(i); }, null, true, 'America/Los_Angeles'); }
when i run the code above ,i get 2 2 rather than 0 1