Created
February 18, 2014 14:17
-
-
Save synzhang/9071821 to your computer and use it in GitHub Desktop.
简易 JavaScript 模块加载器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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