Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 高分子元件中的调用函数_Javascript_Polymer_Polymer 1.0_Firebase Polymer - Fatal编程技术网

Javascript 高分子元件中的调用函数

Javascript 高分子元件中的调用函数,javascript,polymer,polymer-1.0,firebase-polymer,Javascript,Polymer,Polymer 1.0,Firebase Polymer,我正在努力调用聚合元素中的函数。我知道您需要使用this.functionName(),它可以工作 但是当我在像这样的setTimeout中时:runSoon=setTimeout(this.runNow(),12000)无需等待即可运行。 如果我这样写:runSoon=setTimeout(function(){this.runNow()},12000)它给我一条错误消息:未捕获类型错误:this.runNow不是函数 此外,当我在Firebase中使用this.functionName时,它

我正在努力调用聚合元素中的函数。我知道您需要使用
this.functionName(),它可以工作

但是当我在像这样的setTimeout中时:
runSoon=setTimeout(this.runNow(),12000)无需等待即可运行。
如果我这样写:
runSoon=setTimeout(function(){this.runNow()},12000)
它给我一条错误消息:
未捕获类型错误:this.runNow不是函数

此外,当我在Firebase中使用this.functionName时,它可以工作,但在“forEach”中,就像在本例中一样,它给出了我的错误
未捕获类型错误:this.myFunction不是一个函数

ref.once('value', function(snapshot) {
  snapshot.forEach(function(child) {
    this.myFunction();
  });
});

谢谢

应该没有
()

通过这种方式,可以将引用传递给函数this.runNow

runSoon = setTimeout(this.runNow(), 12000);

this.runNow()
的结果传递给
设置超时(…)
它应该没有
()

通过这种方式,可以将引用传递给函数this.runNow

runSoon = setTimeout(this.runNow(), 12000);

this.runNow()
的结果传递给
设置超时(…)

是。这很有效。但是现在我尝试从runNow调用另一个函数,this.nextStep(),它给了我一条错误消息:“uncaughtypeerror:this.nextStep不是函数”。另外,我做的第二种方法应该是有效的。尝试
this.runNow.bind(this)
而不仅仅是
this.runNow
是的,这在JS.yep中很关键(也很麻烦)。这很有效。但是现在我尝试从runNow调用另一个函数,this.nextStep(),它给了我一条错误消息:“uncaughtypeerror:this.nextStep不是函数”。另外,我做的第二种方法应该是有效的。尝试
this.runNow.bind(this)
而不仅仅是
this.runNow
是的,这在JS中很关键(也很麻烦)。