如何在SpookyJS中调用函数



我有一个函数叫clickMore:

function clickMore(max, i){
   i = i || 0;
   if ((max == null || i < max) && this.visible(moreButton)) { // synchronous
      // asynchronous steps...
      this.thenClick(moreButton);  // sometimes the click is not properly dispatched
      this.echo('click');
      this.waitUntilVisible(loadingButton);
      this.waitUntilVisible(moreButton, null, function onTimeout(){
         // only placeholder so that the script doesn't "die" here if the end is reached
      });
      this.then(function(){
         //this.capture("business_"+i+".png");   //captures a screenshot of the page
         clickMore.call(this, max, i+1); // recursion
      });
   }
}

我想从spooky中调用这个函数:

spooky.then(function(){
              clickMore.call(spooky);
          })

我已经浏览了Spooky文档,知道我可能需要使用函数元组,但不确定如何实现。我该怎么做呢?

更新:

尝试使用SpookyJS文档中的函数元组,但没有成功:

spooky.then([{
   clickMore: clickMore
}, function(){
    clickMore.call(spooky);
}]);

传递给spooky.then的函数将在Casper/PhantomJS JavaScript环境中执行。他们不能访问Spooky的Node.js环境。

spooky.then([{
   clickMore: clickMore
}, function(){
    clickMore.call(spooky); // <- spooky is not defined here
}]);

请再看一下介绍维基页面上关于JavaScript环境的内容,以及它们是孤立的。

最新更新