Interesting issue here, Im using injectJs to load an external file (site.js) into my phantomJs/CasperJs script. Its loading fine, but the functions are not evaluating and are returning as strings.
Here is site.js:
var site = function(){
this.getName = function(){
return 'this is a name';
}
}
Here's my phantom.js script:
casper.start();
casper.then(function(){
phantom.injectJs('/path/to/site.js');
mysite = new site(casper);
name = mysite.getName;
this.echo(name);
});
I would expect the console to print out: 'this is a name', But instead it prints out: 'function(){ this.getName = function(){ return 'this is a name'; }}'
I tried eval()ing it as well to no avail (eval?).
Thanks for your help.
You forgot the ()
:
name = mysite.getName();