1

这里有趣的问题,我使用 injectJs 将外部文件(site.js)加载到我的 phantomJs/CasperJs 脚本中。它的加载很好,但函数没有评估并且作为字符串返回。

这是site.js:

var site = function(){
     this.getName = function(){
         return 'this is a name';
     }
}

这是我的 phantom.js 脚本:

casper.start();

casper.then(function(){
    phantom.injectJs('/path/to/site.js');
    mysite = new site(casper);
    name = mysite.getName;
    this.echo(name);

});

我希望控制台打印出:'this is a name',但它会打印出:'function(){ this.getName = function(){ return 'this is a name'; }}'

我也试过 eval() 无济于事(eval?)。

谢谢你的帮助。

4

1 回答 1

1

你忘记了()

name = mysite.getName();
于 2013-01-12T19:59:10.887 回答