Javascript 基本Require.js初始化

Javascript 基本Require.js初始化,javascript,jquery,backbone.js,requirejs,Javascript,Jquery,Backbone.js,Requirejs,我不擅长使用require.js处理导入,我的问题很简单,假设我有这个require的config.js脚本: require.config({ paths: { jquery: 'libs/jquery/jquery', underscore: 'libs/underscore/underscore', backbone: 'libs/backbone/backbone' } }); 这是我在index.html中加入的第一个脚本: <script da

我不擅长使用require.js处理导入,我的问题很简单,假设我有这个require的config.js脚本:

require.config({
  paths: {
    jquery: 'libs/jquery/jquery',
    underscore: 'libs/underscore/underscore',
    backbone: 'libs/backbone/backbone'
  }
});
这是我在index.html中加入的第一个脚本:

<script data-main="config.js" src="require.js"></script>

从现在开始,我可以使用jQuery$、下划线等,还是应该在index.html中导入这样的库?令人费解的是,它有时是如何工作的,有时不是,所以我想我做得不对

编辑:我将在这里更好地解释我的问题:

(一)


$(“分割条”)。。。
//其他一些jquery
//一些使用require的脚本
jQuery是否在此页面中加载了两次


2) 我有一些库需要jQuery才能工作,我可以将它们添加到require配置中的路径吗?

您需要模块并提供回调函数来使用它们:

require(['jquery', 'underscore', 'backbone'],
function   ($,        _,   backbone) {
    //the modules are all
    //loaded and can be used here now.
});

在index.html中,您尝试在哪里使用它?在我看来,这很好,但也许有一个完整的工作示例会有所帮助。这帮助了我:
require(['jquery', 'underscore', 'backbone'],
function   ($,        _,   backbone) {
    //the modules are all
    //loaded and can be used here now.
});