Skip to content

Instantly share code, notes, and snippets.

@synzhang
Created February 18, 2014 14:17
Show Gist options
  • Select an option

  • Save synzhang/9071821 to your computer and use it in GitHub Desktop.

Select an option

Save synzhang/9071821 to your computer and use it in GitHub Desktop.
简易 JavaScript 模块加载器
/**
* @desc Module Loader
* @see http://leechan.me/?p=1241
*/
;(function(global){
var mapping = {}, cached = {};
global.define = function(id, func){
mapping[id] = func;
};
global.require = function(id){
if(cached[id])
return cached[id];
else
return cached[id] = mapping[id]({});
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment