Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
requirejs-这里到底要做什么?_Requirejs - Fatal编程技术网

requirejs-这里到底要做什么?

requirejs-这里到底要做什么?,requirejs,Requirejs,我使用require.js——当我使用requiredjs时,如果不使用shim的导出模式,我就无法在控制台上获得下划线和主干线 但是jquery没有询问此导出。。那么,为什么我们需要为下划线和主干使用垫片及其导出呢 这是我的密码: requirejs.config({ baseUrl: 'js', paths: { "jquery":'lib/jquery-1.9.1.min', "underscore":"lib/underscore-min"

我使用require.js——当我使用requiredjs时,如果不使用shim的导出模式,我就无法在控制台上获得下划线和主干线

但是jquery没有询问此导出。。那么,为什么我们需要为下划线和主干使用垫片及其导出呢

这是我的密码:

requirejs.config({
    baseUrl: 'js',
    paths: {
        "jquery":'lib/jquery-1.9.1.min',
        "underscore":"lib/underscore-min",
        "backbone" : "lib/backbone-min"
    },
    shim:{
        "underscore":{
            exports: '_' 
                   //what is does here? without this i am getting undefined
        },
        "backbone":{
            exports: 'Backbone' 
                    //what is does here? without this i am getting undefined
        }
    }
});

    require(["jquery","underscore","backbone"],function ($,_,Backbone) {
        console.log($,_,Backbone);
//without shim export i am getting conosle like this:
// "function(), undefined, udefined" - why?
    });

主干
下划线
不符合AMD,它们将自身存储在全局范围内(即在浏览器环境中的
窗口
元素中)
shim
元素允许通过将全局变量(下划线为
,主干为
Backbone
)与“虚拟”模块(我称之为“虚拟”)的“导出”部分“链接”来公开它们的全局变量,就像它们是AMD模块一样因为这是动态发生的,所以您不必更改任何代码)

这:

意味着在“下划线”上添加依赖项将获取对
窗口的引用。\u
并将其作为AMD模块公开



jQuery
不需要它,因为它会检测它是否作为AMD模块加载,并在这种情况下以符合AMD的方式暴露自己(向下滚动到最底部以了解更多详细信息)

主干线和
下划线
不符合AMD,它们将自己存储在全局范围内(即,在浏览器环境中的
窗口
元素中)。
shim
元素通过将全局变量(下划线为
,主干为
主干为
主干)与“虚拟”模块(我称之为虚拟”模块)的“导出”部分“链接”,允许公开它们的全局变量,就像它们是AMD模块一样“虚拟”因为这是动态发生的,所以您不必更改任何代码)

这:

意味着在“下划线”上添加依赖项将获取对
窗口的引用。\u
并将其作为AMD模块公开


jQuery
不需要它,因为它检测到它是否作为AMD模块加载,并在这种情况下以符合AMD的方式暴露自己(向下滚动到最底部以了解更多详细信息)

"underscore":{
    exports: '_' 
}