Can .js file "include" another .js file
This question already has an answer here:
If you mean in a browser context, not directly, but you can use a loader like at RequireJS (there are several).
Or to do it manually:
var script = document.createElement('script');
script.src = "/path/to/the/other/file.js";
document.getElementsByTagName('script')[0].parentNode.appendChild(script);
Note, though,that with the above the functions and such in the other file won't be available for use right away. The code above starts the process of loading the file, but it continues asynchronously. You can use events to know that the load is complete (primarily the load
event, but on older versions of IE you have to use onreadystatechange
-- this is one reason people use loaders!).
下一篇: 可以.js文件“包含”另一个.js文件