node模块机制
var sum = 0;
var args = arguments;
var len = args.length;
for(var i = 0;i < len;i++){
var num = args[i];
sum += num;
}
return sum;
}
var math = require('./math');
exports.increment = function(val){
return math.add(val, 1);
};
var increment = require('./increment.js');
require.load = function (context, moduleName, url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
eval(xhr.responseText);
//Support anonymous modules.
context.completeLoad(moduleName);
}
};
};
}());
// script processing rules learned from RequireJS
// TODO: pass a validate function into loadScript to check if a success really is a success
// insert script
var el = doc.createElement('script');
// initial script processing
function process (ev) {
ev = ev || global.event;
// detect when it's done loading
// ev.type == 'load' is for all browsers except IE6-9
// IE6-9 need to use onreadystatechange and look for
// el.readyState in {loaded, complete} (yes, we need both)
if (ev.type == 'load' || readyStates[el.readyState]) {
delete activeScripts[def.id];
// release event listeners
el.onload = el.onreadystatechange = el.onerror = ''; // ie cries if we use undefined
success();
}
}
function fail (e) {
// some browsers send an event, others send a string,
// but none of them send anything useful, so just say we failed:
failure(new Error('Syntax or http error: ' + def.url));
}
// set type first since setting other properties could
// prevent us from setting this later
// actually, we don't even need to set this at all
//el.type = 'text/javascript';
// using dom0 event handlers instead of wordy w3c/ms
el.onload = el.onreadystatechange = process;
el.onerror = fail;
// js! plugin uses alternate mimetypes
el.type = def.mimetype || 'text/javascript';
// TODO: support other charsets?
el.charset = 'utf-8';
el.async = !def.order;
el.src = def.url;
// loading will start when the script is inserted into the dom.
// IE will load the script sync if it's in the cache, so
// indicate the current resource definition if this happens.
activeScripts[def.id] = el;
head.insertBefore(el, insertBeforeEl);
// the js! plugin uses this
return el;
最新文章
- yii框架的理解
- Android开发App工程结构搭建
- 19. javacript高级程序设计-E4X
- iOS-生成国际化包-配置App多语言支持
- SQL Server2005中使用XML-数据类型、查询与修改
- Example018主页加载时获取焦点
- mysql commit 和 rollback
- Linux下批量杀掉 包含某个关键字的 程序进程
- Spring -- <;mvc:annotation-driven />;
- python练习题_01
- <;转>; plsql dev中Dynamic Performance Tables not accessible分析解决
- Spark代码中设置appName在client模式和cluster模式中不一样问题
- 牛客训练四:Applese 的回文串(思维)
- 魔法少女【动态规划问题】——NYOJ1204
- mybatis之DAO层自动实现接口
- 【Python】使用torrentParser1.02对多文件torrent的分析结果
- 树莓派的媒体播放软件omxplayer
- express 重新加载
- Codeforces 946D Timetable(预处理+分组背包)
- (CLR via C#学习笔记)线程基础