简体   繁体   English

流星计时器中的Meteor.setTimeout()问题?

[英]Meteor.setTimeout() issue in Meteor Timers?

I did a sample example on Meteor.setTimeout() using Meteor . 我使用MeteorMeteor.setTimeout()上做了一个示例。 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 : 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
  });


}

The problem is that setTimeout expects a function as a first parameter but you are passing the result of evaluating Test("10") which is "undefined". 问题是setTimeout需要一个函数作为第一个参数,但是你传递的是评估Test("10")的结果,它是“未定义的”。

You can solve the issue by wrapping your call to Test1 in an anonymous function: 您可以通过在匿名函数中包含对Test1的调用来解决此问题:

Meteor.setTimeout(function(){Test("10");}, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM