RequireJS


Well, i heard of this a while ago, but i never really payed too much attention to it. I was honestly kinda afraid of it, it sounded very advanced and complicated. But yesterday i decided to face this thing and read the documentation. After a while of doing some tests, i loved it! Now i cant go back to my old coding style. AMD Pattern FTW!!

I DID was very anoyed in the past to not know the dependencies of the code i was reading, or having to deal with the loading of them.

RequireJS deals with the loading and definition of Modules. This is something i got a hard time understanding at first. You have basically 2 main functions when working with RequireJS:

1) require(…) = Used to start the loading of the modules you are asking in the parameters. It will load all the dependencies and call a callback after everything gets loaded. You can even have modules that load other modules, and so on. That´s kinda cool.

2)define(…) = This is what you use to declare modules. RequireJS is build arround the AMD Pattern.

Here you have a nice slide with more info: http://unscriptable.com/code/Using-AMD-loaders/#0

So, to start using this pattern/loader you have to wrap all your code in modules, and ask for them using require or define (if you are defining a module that uses another module as a dependencie)

 

Advertisements