I found that RequireJS has became one of my favorite library, so I need to know it deeply to make it my strong point. This article is log of code reading for 2.0.4.
require.js
- it has many helper like bind(), mixin() and each().
- IE6 support: there is a comment "When that browser dies, this can be removed"...
- handling error: overriding this method or putting break point here will help me to debug.
- it has good comments to tell WHY. see about web worker and IE9 support
- there is many
if (isBrowser)
so I guess that we can create shorten version which supports only browser. - we can put data-main attribute into <script> tag which doesn't load require.js (of course we should put it for <script src="require.js"> normally). see here.
- the way to support
shim.deps = array;
is very simple.
r.js
This script is too complex for me... It contains esprima and uglifyjs. We don't have to code long script like this because we can use r.js, we should say thanks for contributors.
- to supports both of rhino and Node.js, it checks predefined variable.
- it hides global variable which Node.js defined. hiding defined one is one of the interest character of JavaScript for me.
- it contains framework to handle event and callback like spine.js. I agree that event driven fits JavaScript. require.js also has these methods.