If the AMD specification is used in Requirejs, there are not many problems in using it, and if you load a JS file that is not an AMD specification, you will need to use shim in require.
Require.config ({ paths:{ jquery: "/js/jquery2.0", instorage: "/js/in/instorage", Product: "/js/ Product/product ", Cate:"/js/product/category ", }, shim:{ cate:{ deps:[], exports:" Category " }}} );
Cate: "/js/product/category" This file is non-AMD specification JS, in the process of using to follow the following several steps:
(1) Paths in the configuration file loading path, JSON key value can be arbitrary, as meaningful as possible, the value in JSON is the file loading path, this needless to say
(2) A JSON object is defined in shim, and the Key value (Cate) is the same as the name defined in paths
(3) The JSON object in Shim has two properties: deps,exports; Deps An array that represents the library it relies on, and exports represents the object name of the output
var category= (function () { var param={}; Param. Add=function () { console.log ("new category"); } return param;}) (); var category= (function (param) { param. Write=function () { console.log ("Output classification information"); } return param;}) (category| | {});
Requirejs can realize the delay loading of JS, loading JS When the method is called, that is, require the information of a module in function.
Define (function () { var productmanager={ create:function () { Console.log ("Create Product"); Require (["Cate"],function (Cate) { cate. Write (); Cate. Add (); }); } } return productmanager;});
(EXT) Requirejs shim usage notes