如何在另一个不在浏览器内运行的 JavaScript 文件中包含 JavaScript 文件? [英] How to include a JavaScript file in another JavaScript file THAT IS NOT RUN FROM INSIDE A BROWSER?
本文介绍了如何在另一个不在浏览器内运行的 JavaScript 文件中包含 JavaScript 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道以前有人问过很多类似的问题.与我的情况不同的是,我使用的是 Windows Scripting Host 并从 DOS 命令行运行脚本,而不是从浏览器内部运行.
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, not from inside a browser.
我能想到的唯一方法是使用 fso.OpenTextFile(ThisFile, 1)
从磁盘读取文件作为文本,然后使用 eval
函数将文本视为代码.
The only way I can think of doing this is to read the file from the disk as text using fso.OpenTextFile(ThisFile, 1)
, and then using the eval
function to treat the text as code.
有没有更方便的方法?
推荐答案
据我所知,不,这是唯一真正的选择.示例:
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";
function foo() {
WScript.Echo("foo");
}
输出:
foo
testing
这篇关于如何在另一个不在浏览器内运行的 JavaScript 文件中包含 JavaScript 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文