I'm trying to use node-schedule, and I wanna use current data in future. So my code is:
var j = schedule.scheduleJob({
start: new Date().setHours(data[i].start_hour, data[i].start_minute),
end: new Date().setHours(data[i].end_hour, data[i].end_minute),
rule: '*/'+distance_run+' * * * * *'
}, function (data) {
console.log("333", data)
}).bind(null, data[i]);
But it have error: schedule.scheduleJob(...).bind is not a function
Help me please!
scheduleJob() doesn't return a function that can be executed. If you want to use data[i]
inside the function, you can pass data[i]
bound function as second argument like,
var j = schedule.scheduleJob({
start: new Date().setHours(data[i].start_hour, data[i].start_minute),
end: new Date().setHours(data[i].end_hour, data[i].end_minute),
rule: '*/'+distance_run+' * * * * *'
}, function (data) {
console.log("333", data)
}.bind(null, data[i]) );