【问题标题】:Phantom Js, CasperJs External scripts not evaluating properlyPhantom Js、CasperJs 外部脚本未正确评估
【发布时间】:2013-01-13 03:59:10
【问题描述】:

这里很有趣,我使用 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);

});

我希望控制台打印出:“这是一个名字”, 但它会打印出: 'function(){ this.getName = function(){ return 'this is a name'; }}'

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

感谢您的帮助。

【问题讨论】:

    标签: javascript server-side phantomjs casperjs


    【解决方案1】:

    你忘了():

    name = mysite.getName();
    

    【讨论】:

    • 天啊,我觉得自己很笨......谢谢。
    • Np,它有时会发生在我们所有人身上;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 2014-08-14
    • 1970-01-01
    相关资源
    最近更新 更多