How can I create a javascript library in a separate file and quot;includequot; it in another?(如何在单独的文件中创建 javascript 库并“包含?它在另一个?)
问题描述
首先,请注意.主脚本不在网页中运行.我将使用 Windows Script Host 在 Windows 中运行 .js 文件.
First, a caveat. The main script is not run in a webpage. I will be running the .js file in Windows using Windows Script Host.
问题:我想创建一个包含许多对象的javascript库",每个对象都有许多功能.我预计这个库会随着时间的推移变得相当大,并希望将它保存在一个单独的 javascript 文件中(我们称之为 Library.js).我想从另一个脚本(我们称之为 User.js)访问 Library.js 中的对象.
The problem: I would like to create a javascript "library" containing a number of objects, each with a number of functions. I expect this library will get rather large with time and would like to keep it in a separate javascript file (let's call it Library.js). I would like to access the objects from Library.js from another script (let's call this one User.js).
本质上,我正在寻找类似于 C/C++包含"范式的东西.
In essence, I am looking for something similar to the C/C++ "include" paradigm.
有没有办法在 javascript 中实现这个?(记住,这不是基于网络的)
推荐答案
这个页面就在这里是我能找到的最接近的.它讨论了 .wsf 文件,它可以让您将多个脚本(可能用不同的语言编写)组合在一个文件中.
This page right here is the closest I could find. It talks about .wsf files which let you combine multiple scripts (that may be written in different languages) in one file.
你的问题应该是这样的:
For your question it should be something like:
user.wsf
<job id="IncludeExample">
<script language="JScript" src="library.js"/>
<script language="JScript">
<![CDATA[
// use your library functions here
]]>
</script>
</job>
可能有更好的方法,但我不是 WSH 专家.
There may be better ways, but I'm not a WSH expert.
这篇关于如何在单独的文件中创建 javascript 库并“包含"?它在另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在单独的文件中创建 javascript 库并“包含"?它在另一个?


基础教程推荐
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01