Using RequireJS in our project

To convert our modules into RequireJS-compatible modules, we will define them using the AMD specification. This specification says that to define a module you need to call the define function. This function receives an array that contains strings. These strings represent paths or aliases from the configuration file for each dependency (files required in the module).

The second parameter that the define function needs is a function that will return the module. This function will have dependencies from the array as arguments. The good thing with this pattern is that code inside the define function will not be executed until all dependencies are loaded. The following is what the define function will look like:

define(['dependency1','dependendency2'],function(dependency1,depencency2){ ...

Get KnockoutJS Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.