I need a solution for managing js files in my project.
我需要一个管理项目中的js文件的解决方案。
Is there any way that i can reference a js file like this in my html?
有什么办法可以在我的html中引用这样的js文件吗?
<script>
var someName = use("somejsfile.js")
</script>
And to use it like this
并像这样使用它
<input onclick="someName.saveThisInput()">
Currently the js file in my project is made like this:
目前我的项目中的js文件是这样的:
$( document ).ready(function() {});
var abc = "some global var";
// a lot of other globals
function saveThisInput(){}
function saveThisInput1(){}
function saveThisInput2(){}
EDIT
I can't make any changes to the preexisting js files so require.js won't work. My goal is to merge two or more such js files having name conflicts
我无法对预先存在的js文件进行任何更改,因此require.js将无法正常工作。我的目标是合并两个或多个具有名称冲突的js文件
1 个解决方案
#1
0
you can use namespace in js edit the js file to look like:
你可以在js中使用命名空间编辑js文件,如下所示:
var hello = {
world: function() {
alert("hello world!");
},
foo: function() {
alert("foo");
}
};
and use it like:
并使用它像:
hello.world();
#1
0
you can use namespace in js edit the js file to look like:
你可以在js中使用命名空间编辑js文件,如下所示:
var hello = {
world: function() {
alert("hello world!");
},
foo: function() {
alert("foo");
}
};
and use it like:
并使用它像:
hello.world();