I am writing some server-side scripts using JScript and WSH. The scripts are getting quite long, and some common functions and variables would fit better in a general librar
Based on Thomas's solution — here's a similar, but more modular approach. First, the script to call:
/* include.js */
(function () {
var L = {/* library interface */};
L.hello = function () {return "greetings!";};
return L;
}).call();
Then, in the calling script:
var Fs = new ActiveXObject("Scripting.FileSystemObject");
var Lib = eval(Fs.OpenTextFile("include.js", 1).ReadAll());
WScript.echo(Lib.hello()); /* greetings! */
Libraries defined this way don't produce or rely on any upvalues, but the eval will return any value it receives from the surrounding anonymous-function in the library.