Javascript 如何在另一个js文件中包含代码的js部分。[预印本]

Javascript 如何在另一个js文件中包含代码的js部分。[预印本],javascript,jquery,file,concatenation,prepros,Javascript,Jquery,File,Concatenation,Prepros,Prepos具有以下有用的功能: //@prepros-prepend filename.js 其中包括当前语句开头的js文件,但我需要在jquery document.ready语句中包含文件,如下所示: $(function(){ //@prepros-include code1.js //@prepros-include code2.js //@prepros-include code3.js //@prepros-include code3.js ... });

Prepos具有以下有用的功能:

//@prepros-prepend filename.js
其中包括当前语句开头的js文件,但我需要在jquery document.ready语句中包含文件,如下所示:

$(function(){
  //@prepros-include code1.js
  //@prepros-include code2.js
  //@prepros-include code3.js
  //@prepros-include code3.js
  ...
});
这是否有可能,或者您是否有任何其他解决方案来连接将绑定在jquery
$(function(){…})中的大量js片段包装器


[编辑]Ps.我不想写
$(function(){…})在每个部分文件中。

如果你使用谷歌,第一个链接将是 但是,如果您想在js文件中包含其他js文件,请使用此选项

$.getScript( "ajax/test.js" )
  .done(function( script, textStatus ) {
    console.log( textStatus );
  })
  .fail(function( jqxhr, settings, exception ) {
    alert("No file found");
});
当然,你可以很容易地画出这样的线条

$.getScript( "ajax/test.js" );

您最好的解决方案可能类似于或。我感兴趣的是将文件连接到一个输出代码中,在这种情况下,Ajax请求会影响页面加载时间,并且不会在文件:///协议上工作,这在很少情况下是一件有用的事情,因为它不需要设置web服务器。另外,如果我决定使用ajax解决方案,我会使用Require.js而不是jquery