过去几天我一直在玩requirejs.我试图理解define和require之间的区别.
定义似乎允许模块分离并允许遵守依赖性排序.但它会下载所需的所有文件.虽然只需要在您需要时加载您需要的东西.
这两者可以一起使用,是否应该使用它们?
我从这里读api的requirejs文件
requirejs.config({
shim: {
'backbone': {
//These script dependencies should be loaded before loading
//backbone.js
deps: ['underscore', 'jquery'],
//Once loaded, use the global 'Backbone' as the
//module value.
exports: 'Backbone'
},
'underscore': {
exports: '_'
},
'foo': {
deps: ['bar'],
exports: 'Foo',
init: function (bar) {
//Using a function allows you to call noConflict for
//libraries that support it, and do other cleanup.
//However, plugins for those libraries may still want
//a global. "this" for the …Run Code Online (Sandbox Code Playgroud)