I did a sample example on Meteor.setTimeout()
using Meteor
. In this example i get an error. I didn't have any idea about this.So please see the below code,error and suggest me how to do?
Error :
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
});
}
I did a sample example on Meteor.setTimeout()
using Meteor
. In this example i get an error. I didn't have any idea about this.So please see the below code,error and suggest me how to do?
Error :
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
});
}
Share
Improve this question
edited Jan 28, 2014 at 10:17
user3213821
asked Jan 28, 2014 at 10:08
user3213821user3213821
2291 gold badge3 silver badges10 bronze badges
1
|
1 Answer
Reset to default 22The problem is that setTimeout
expects a function as a first parameter but you are passing the result of evaluating Test("10")
which is "undefined".
You can solve the issue by wrapping your call to Test1
in an anonymous function:
Meteor.setTimeout(function(){Test("10");}, 1000);
Meteor.setTimeout
is only necessary on the server, because server code must run within a Fiber. There are no Fibers on the client, so you can just use the regular globalwindow.setTimeout
. That said, you must pass a function object as @Tobold pointed out. – sbking Commented Jan 28, 2014 at 18:41