2

I am a newbie in JavaScript. I have been reading PhantomJS and CasperJS API. All the time I see the following line of code

in CasperJS

var casper = require('casper').create(); 

in PhantomJS

var webPage = require('webpage').create();

We can replace the above lines with

in CasperJS

var casper = new require('casper').Casper()

in PhantomJS

var WebPage = require('webpage');
var webPage = new WebPage();

Based on what I know, CasperJS is testing utility sit on top of PhantomJS environment. I'm guessing that the require function has the same underlying implementation for both CasperJS and PhantomJS.

I have been search around for the API reference to the require function, but I couldn't find any.

Would be nice if someone can guide me to the right path.

  1. What does the require function do? (is it similar to the functionality of using keyword in C# .net)

  2. Where does PhantomJS reference the "require" function from? (is it using its own implementation or is it referencing another javascript framework?)

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
James Le
  • 21
  • 3
  • It is best to stick to the `.create()` type initialization, because additional checks are performed there which ensure that the script functions properly. – Artjom B. Dec 13 '14 at 10:26
  • Yes thanks everyone. The other thread got my confusion clear. Thank you – James Le Dec 15 '14 at 18:51

0 Answers0