我有一个文件叫common.js
它包含在我的网站的每个页面使用<script />
。自动加载/包括JavaScript
随着我的网站功能增长(我希望;我想象)它会快速增长。 :)
让例子,我有一个jQuery事件:
$('#that').click(function() {
one_of_many_functions($(this));
}
就目前而言,我有one_of_many_functions()
在common.js
。
当某个函数被调用时,JavaScript会自动加载文件one_of_many_functions.js
,但它不存在吗?像自动装载机一样。 :)
我看到的第二个选择是做这样的事情:不是这样自动
$('#that').click(function() {
include('one_of_many_functions');
one_of_many_functions($(this));
}
,但仍 - 包含所需文件。
这是可能的吗?谢谢你的建议! :)
这听起来像你真的很喜欢[RequireJS](http://requirejs.org/) –