jint

JINT - Can External Javascript be Included in parsing?


I am wanting to implement JINT in my website, with Ace text editor for the management to write some scripting situations in javascript. So far this looks to be fine, but I am having a hard time finding some specific information.

Essentially, I need to create some certain javascript "objects" with some functions attached to them. In normal javascript this is no problem, but I am curious if JINT can handle this scenario and allow me to load these objects from a *.js file when it is getting ready to run the scripts? I have dug around on this topic and not found a lot of answers; Primarily the only semi-conclusion I discovered was here; Stackoverflow Question

Any help is appreciated, as I am new to this entire concept of JINT and find it an interesting approach.. but with a lot of confusion. If there are other engines similar to JINT but better suited to this, recommendation would also be appreciated.


Solution

  • Once you have instantiated the Engine object, you can call Execute() as many times as you want. So what you will do is before executing the script from your text editor, just execute the scripts that you want to include.

    This should be something like this:

    var script1 = System.IO.File.ReadAllText('script1.js');
    var script2 = System.IO.File.ReadAllText('script2.js');
    
    var engine = new Jint.Engine();
    engine.Execute(script1);
    engine.Execute(script2);
    engine.Execute(aceditor.Text);