如何从另一个引用 JScript 文件?
我正在使用 JScript 和 WSH 编写一些服务器端脚本.脚本变得很长,一些常用函数和变量更适合我包含在各种脚本实例中的通用库脚本.
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 library script which I included in my various script instances.
但是,我找不到从另一个引用一个 JScript 文件的方法.有一会儿,我虽然读取文件内容并将其传递给 eval()
可以工作.但是,正如 MSDN 上所说:
But, I cannot find a way reference one JScript file from another. For a moment, I though reading the file contents and passing it to eval()
could work. But, as it says on MSDN:
请注意,在 eval 语句中定义的新变量或类型对封闭程序不可见.
Note that new variables or types defined in the eval statement are not visible to the enclosing program.
有什么方法可以包含/引用另一个 JScript 文件?
Is there any way to include/reference a JScript file from another one?
推荐答案
尝试使用 Windows 脚本文件.它基本上是一个 XML 文档,它允许您包含多个脚本文件并定义多个作业等.
Try using a Windows Script File. It's basically an XML document which allows you to include multiple script files and define multiple jobs, amongst other things.
<!-- MyJob.wsf -->
<job id="IncludeExample">
<script language="JScript" src="MyLib1.js"/>
<script language="JScript" src="MyLib2.js"/>
<script language="JScript">
WScript.Echo(myLib1.foo());
WScript.Echo(myLib2.bar());
</script>
</job>
相关文章