Detailed source code altogether more than 2000 lines, to see me this analysis classmate should all download down, OK, words not to say, start:
3 global variables appear at the beginning of the code: REQUIREJS, Require, define
var Requirejs, require, define; (function (Global, setTimeout) {Balababla ...}) (This, (typeof setTimeout = = = ' undefined '? undefined:settimeout)))
Require and define everyone should know what to do, to tell the truth, I do not know, in the analysis of the code, I have never used this framework, have heard AMD, just to see the source directly.
If you are not very clear, these 2 variables is what to do, I would like to introduce briefly, understand the classmate if I said wrong, I hope to guide me also a bit.
Main Page index.html:
Note that SRC is the introduction of our Requirejs Library, Data-main: That's where we first used Requrie:
Main.js:
Here are 2 blocks of code that are dependent on require:
(1) Require.config: Configuration
(2) Requrie (); Load the required functions, note that the [' name ', ' say '] are all filenames, and they are all in the./js/directory, specifically see CONIFG
Require.config ({ baseUrl: ', paths: { ' namedep ': ' JS/NAMEDEP ', ' say ': ' Js/say ', ' name ': ' js/ Name ' }, shim: { ' name ': { deps: [' NAMEDEP '}}}}, require ([' name ', ' say '], function ( Name, say) { say (name);});
./js/name.js and./js/say.js
Namedefine (['], function () { return ' test ';});
Saydefine ([], function () { return function (name) { console.log (name); };});
Finally note that there is a skim in config, which is also the definition of JS file, just because he may not conform to the AMD-loaded specifications
./js/namedep.js
Console.log ("Namedep.js")
--------------------------------------Split Line-------------------------------------------------------------------------
Step by step you analyze Requirejs