Kengo's blog

Technical articles about original projects, JVM, Static Analysis and JavaScript.

requirejs reading

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.