0

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);
user135498
  • 6,013
  • 8
  • 29
  • 29

1 Answers1

0

Take the () out of your function call.

setInterval(viewModel.displaySomething, 60000);

You can read all about it here Javascript setInterval not working

Community
  • 1
  • 1
tgeery
  • 174
  • 6