我在 Meteor.setTimeout()
上使用 Meteor
做了一个示例。在这个例子中我得到一个错误。我对此一无所知。所以请看下面的代码,错误并建议我怎么做?
错误:
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 代码:
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
});
}
最佳答案
问题是 setTimeout
需要一个函数作为第一个参数,但您传递的是评估 Test("10")
的结果,它是“未定义的”。
您可以通过将对 Test1
的调用包装在匿名函数中来解决此问题:
Meteor.setTimeout(function(){Test("10");}, 1000);
关于javascript - meteor 计时器中的 Meteor.setTimeout() 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21402544/