0

I have been researching for a simple solution to a problem that I have.

I have a JavaScript file that needs to use some functions that are contained in another JS file. I read many posts from stack overflow, and they all require a to be loaded from a web page. In my case they absolutely do not use a web page to be loaded and I do not want to use one.

The reason is because I am running JavaScript unit testing from command line using Rhino. Please I'm begging for help!

7dr3am7
  • 755
  • 1
  • 8
  • 21

2 Answers2

1

You can load in the other javascript file using Ajax. Have a look at jQuery .getScript(). I'm not sure if that'll work in the context of running from the command line, or if it just appends the .js file to the document.body.

duncan
  • 31,401
  • 13
  • 78
  • 99
  • There's more details about doing this in another Stack Overflow post here: http://stackoverflow.com/questions/950087/include-javascript-file-inside-javascript-file – kah608 Dec 09 '11 at 15:32
  • thank you very much for your answer, I already looked at that post @kah608, but the options used they all require a web browser, Thank you Duncan, by chance are you aware of any JavaScript Native commands? Will JQuery need a browser to be loaded though? – 7dr3am7 Dec 09 '11 at 15:47
1

Use Rhino's load function (about a third of the way down this page): https://developer.mozilla.org/en/Rhino_Shell

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141