Created
November 28, 2011 08:33
-
-
Save milesplit/1399624 to your computer and use it in GitHub Desktop.
really really basic common js
This file contains 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
below i'm just mocking up a really simple way to emmulate module/require code similar to commonjs | |
i just threw this together and it doesnt do any loading at all... have another script i could strap that to | |
wonder though if this should be async instead of sync, even though commonjs is synchronous with require | |
<script> | |
window.__loadedModules = {}; | |
window.define = function(n,f){ | |
var exports = {}; | |
f(exports); | |
__loadedModules[n] = exports; | |
}; | |
window.require = function(n){ return __loadedModules[n]; }; | |
// equivalent of external module | |
define('hello world', function(exports){ | |
exports.hello = 'world'; | |
}); | |
// require it | |
var hello = require('hello world'); | |
console.log(hello); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment