Meteor.setTimeout () problem in Meteor timers?

I made an example on Meteor.setTimeout() using Meteor . In this example, I am getting an error. I had no idea about this. So see below code, error and suggest me how to do this?

Mistake:

 Exception in setTimeout callback: TypeError: undefined is not a function at _.extend.withValue (http://localhost:3000/packages/meteor.js?8ec262df25783897eaad01255bc8bd1ca4e78b24:773:17) at http://localhost:3000/packages/meteor.js?8ec262df25783897eaad01255bc8bd1ca4e78b24:358:45 at http://localhost:3000/packages/meteor.js?8ec262df25783897eaad01255bc8bd1ca4e78b24:801:22 

JS Code:

  if (Meteor.isClient) { Meteor.setTimeout(Test("10"), 1000); Meteor.setInterval(Test1, 1000); Template.hello.greeting = function () { return "Welcome to timerapp."; }; Template.hello.events ({ 'click input' : function () { // template data, if any, is available in 'this' if (typeof console !== 'undefined') console.log("You pressed the button"); //Test(); } }); } function Test(x) { console.log("*** Test() ***"+x); } function Test1() { console.log("*** Test1() ***"); } if (Meteor.isServer) { Meteor.startup(function () { // code to run on server at startup }); } 
+8
javascript meteor
source share
1 answer

The problem is that setTimeout expects the function as the first parameter, but you pass the result of evaluating Test("10") , which is "undefined".

You can solve the problem by wrapping the call to Test1 in an anonymous function:

 Meteor.setTimeout(function(){Test("10");}, 1000); 
+20
source share

All Articles