Skip to content Skip to sidebar Skip to footer

How To Include A Javascript File In Another Javascript File That Is Not Run From Inside A Browser?

I know that many similar questions have been asked before. The difference in my case is that I am using Windows Scripting Host and am running the script from the DOS command line,

Solution 1:

As far as I can tell, no, that's the only real option. Example:

text.js:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var ts = fso.OpenTextFile("foo.js");
var script = ts.ReadAll();
eval(script);
foo();
WScript.Echo(bar);

foo.js:

var bar = "testing";
functionfoo() {
    WScript.Echo("foo");
}

Output:

foo
testing

Post a Comment for "How To Include A Javascript File In Another Javascript File That Is Not Run From Inside A Browser?"