RequireJs学习

require会定义三个变量:define,require,requirejs,其中require === requirejs,
其中Define是api的一个模块
 
Require.config用来配置模块加载的位置,
require.config({
paths : { "jquery" : ["http://libs.baidu.com/jquery/2.0.3/jquery", "js/jquery"], "a" : "js/a" }
//非AMD模块输出,将非标准的AMD模块"垫"成可用的模块,例如:在老版本的jquery中,是没有继承AMD规范的,所以不能直接require["jquery"],这时候就需要shim,比如我要是用underscore类库,但是他并没有实现AMD规范,那我们可以这样配置
shim:{
"underscore":{
exports:"_";
}
}
})
给每个模块起一个别名,这样在
require的时候就可以require(["别名","underscore",“js/a”],function($,_){
$(functioin(){
alert("只是个回调函数");
_.each([1,2,3],alert);
})
})
 
RequireJs在Asp.Net 中的应用
 
requirejs配置模块加载
requirejs.config({ paths: {       "jquery": "/js/jquery.min", "bootstrap": "/js/bootstrap"     },     shim: { 'bootstrap': { deps: ['jquery'], exports: "jQuery.fn.popover" }     }   });
 
然后在home.js在引用时:
 
require(['../config'], function () { require(['home.index2']); }) , define("home.index2", ['jquery', 'bootstrap'], function () { //main module code here })
 
原文地址:https://www.cnblogs.com/fuGuy/p/7912903.html