I'm trying to call a method on an object literal using setInterval and can't get it to work. I know I have some kind of context problem and found several other posts discussing the topic but couldn't find the information I needed to get my code working.
Thank you.
var viewModel = {
displaySomething: function () { console.log('displaying something'); },
displaySomethingElse: function () { console.log('displaying something else');}
};
setInterval(viewModel.displaySomething(), 60000);
setInterval(viewModel.displaySomethingElse(), 60000);
Take the () out of your function call.
setInterval(viewModel.displaySomething, 60000);
You can read all about it here Javascript setInterval not working
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.