如何调用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.then(function(){ clickMore.call(spooky); })
我已经看了Spooky文档,知道我可能需要使用一个函数元组,但不知道如何实现。 我怎么能这样做?
更新:
尝试使用SpookyJS文档中的函数元组,但没有运气:
spooky.then([{ clickMore: clickMore }, function(){ clickMore.call(spooky); }]);
传入spooky.then
函数将在Casper / PhantomJS JavaScript环境中执行。 他们没有访问Spooky的Node.js JS环境。
spooky.then([{ clickMore: clickMore }, function(){ clickMore.call(spooky); // <- spooky is not defined here }]);
请再看一下介绍wiki页面对JavaScript环境的描述,以及它们是孤立的 。