requirejs源码分析: define 方法
define = function (name, deps, callback) {
var node, context;//Allow for anonymous modules
if (typeof name !== 'string') {
//Adjust args appropriately
callback = deps;
deps = name;
name = null;
}//This module may not have dependencies
if (!isArray(deps)) {
callback = deps;
deps = null;
}//If no name, and callback is a function, then figure out if it a
//CommonJS thing with dependencies.
if (!deps && isFunction(callback)) {
deps = [];
//Remove comments from the callback string,
//look for require calls, and pull them into the dependencies,
//but only if there are function args.
if (callback.length) {
callback
.toString()
.replace(commentRegExp, '')
.replace(cjsRequireRegExp, function (match, dep) {
deps.push(dep);
});//May be a CommonJS thing even without require calls, but still
//could use exports, and module. Avoid doing exports and module
//work though if it just needs require.
//REQUIRES the function to expect the CommonJS variables in the
//order listed below.
deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
}
}//If in IE 6-8 and hit an anonymous define() call, do the interactive
//work.
if (useInteractive) {
node = currentlyAddingScript || getInteractiveScript();
if (node) {
if (!name) {
name = node.getAttribute('data-requiremodule');
}
context = contexts[node.getAttribute('data-requirecontext')];
}
}//Always save off evaluating the def call until the script onload handler.
//This allows multiple modules to be in a file without prematurely
//tracing dependencies, and allows for anonymous module support,
//where the module name is not known until the script onload event
//occurs. If no context, use the global queue, and get it processed
//in the onscript load callback.
(context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
};
这里的代码比较简单, 主要是把将是将前端的参数 添加到 队列 中。
第一个参数name, 可以自定义当前模块的名称, 用于require时可以使用这个名称进行加载。 现在很少使用这个参数,都使用路径的方法加载模块了。
requirejs源码分析: define 方法的更多相关文章
- requirejs源码分析: requirejs 方法–2. context.require(deps, callback, errback);
上一篇 requirejs源码分析: requirejs 方法–1. 主入口 中的return context.require(deps, callback, errback); 调用的是make ...
- requirejs源码分析: requirejs 方法–1. 主入口
该方法是 主要的入口点 也是最常用的方法. req = requirejs = function (deps, callback, errback, optional) { //Find the ri ...
- mybatis源码分析(方法调用过程)
十一月月底,宿舍楼失火啦,搞得20多天没有网,目测直到放假也不会来了... 正题 嗯~,其实阅读源码不是为了应付面试,更重要的让你知道,大师是怎样去写代码的,同样是用Java,为啥Clinton Be ...
- requirejs源码分析: 路径
1. 没有设置baseUrl(一般我们都会设置baseurl) 在没有设置baseUrl时, 默认 baseurl: "./" 当指定data-mai ...
- cocos2D-x demo 的源码分析 #define ..##.. 的妙用.
最近在看cocos2d-x 但不知道如何下手,于是先看一下他编译的完成的testcpp的源码.发现了下面一段程序 typedef CCLayer* (*NEWTESTFUNC)(); #define ...
- requirejs源码分析: config中shim
shim处理的源码: //Merge shim if (cfg.shim) { eachProp(cfg.shim, funct ...
- requirejs源码分析,使用注意要点
本文将深度剖析require.js代码,为了是大家更高效.正确的去使用它,本文不会介绍require的基本使用! 概要 先来一个流程图来概要一下大概流程 在require中,根据AMD(Asynchr ...
- WorkerMan源码分析(resetStd方法,PHP中STDIN, STDOUT, STDERR的重定向)
WorkerMan中work.php中 resetStd 方法中代码如下 public static function resetStd() { if (!static::$daemonize || ...
- requirejs源码分析
随机推荐
- deepin linux下eclipse c/c++ 调试开源代码
1.deepin linux 下使用eclipse c/c++ 调试2. 编译选项,-g3 -O0,-g3表示输出调试信息,-O0不优化代码(第一个字母o的大写,第二个是数字0) 3.必备环境: gd ...
- Yarn源码分析之MRAppMaster:作业运行方式Local、Uber、Non-Uber
基于作业大小因素,MRAppMaster提供了三种作业运行方式:本地Local模式.Uber模式.Non-Uber模式.其中, 1.本地Local模式:通常用于调试: 2.Uber模式:为降低小作业延 ...
- ntp集群时间同步
1. NTP 简介 网络时间协议(英语:Network Time Protocol,简称NTP)是在数据网络潜伏时间可变的计算机系统之间通过分组交换进行时钟同步的一个网络协议.自1985年以来,NTP ...
- 下载 Microsoft SQL Server JDBC 驱动程序
JDBC 驱动程序中使用 Maven 中心 JDBC 驱动程序可以通过将其添加为依赖项在 POM.xml 文件中使用以下代码添加到 Maven 项目: XML复制 <dependency> ...
- boot2docker里报"no space left on device" error的解决方法
docker中pull远程image时:报 no space left on device virtualbox中调大虚拟内存即可.. 之前调的硬盘大小...
- SlidingMenu官方实例分析2——BaseActivity
本文从BaseActivity说起,因为其他功能页面都继承了这个类. 这里继承了Sliding中的SlidingFragmentActivity,其实也可以继承SlidingActivity, 但是现 ...
- java的一些问题
1. 判断是否是奇数: public static boolean isOdd(int i) { return i %2 != 0 ; } 2. System.out.println(2.0 - 1. ...
- docker搭建lnmp环境(问题,资料,命令)
入门参考 http://www.runoob.com/docker/docker-install-nginx.html 十大常用命令玩转docker 1. #从官网拉取镜像 docker pull & ...
- Jmeter与LoadRunner 测试Java项目的坑
32位的JDK,Jmeter.bat 最大内存只能配置1G,测不了大并发,所以用Jmeter测试时一定要改成64位的Jmeter用LR测试java程序的时候必须用32位的JDK 环境变量 在path的 ...
- LR测试文件上传
开启fiddler 录制,回放,把上传文件放入脚本根目录中.