Book Image

KnockoutJS Essentials

By : Jorge Ferrando, Jorge F Ferrando
Book Image

KnockoutJS Essentials

By: Jorge Ferrando, Jorge F Ferrando

Overview of this book

Table of Contents (16 chapters)
KnockoutJS Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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){
  //you can use depencencies here, not outside.
  var Module = //can be a literal object, a function.
  return Module; 
});

The function should always return the module variable, or...