4 ms·
Well, there isn't actually any module loading. The define function lets you define new modules with dependencies. The require function returns a reference to a
by bgrohman 15y ago
Well, there isn't actually any module loading. The define function lets you define new modules with dependencies. The require function returns a reference to a module or throws an exception if it hasn't been loaded.
The idea is that you get to use CommonJS-style module definition in conjunction with old-school script loading using script tags. This could be used during a transition of a large project to something more robust like RequireJS. Or it could be used if your application has to support high-latency connections where you need to minimize the number of HTTP requests.
- firefoxman1 15y agoAhh I see. That's really cool! No bloat and easy to use. I'll have to consider this for my next project. Honestly I think CommonJS gets too much flack. It's bounds better than ECMAScript Harmony's module draft.
- bgrohman 15y agoThanks! Yeah, ECMAScript Harmony's module proposal uses new syntax, which basically means most developers won't be able to use it for a while. Also, I'm not sure if Harmony supports loading/using multiple modules defined in a single file.