So I've been using require.js for while now, but I realized that I actually don't know how it works under the hood. It says that it's an AMD loader.
I do understand that CommonJS is synchronous, which means that it blocks execution of other codes while it's being loaded. On the other hand, AMD is asynchronous. This is where I get confused.
When I define a module, it has to load a,b,c in order to execute the callback. How does asynchronous work here?
- Isn't it synchronous when it has to load those three dependencies first?
- Does it mean that AMD loads a,b,c asynchronously then checks to see if those files are loaded (doesn't care about the order) then execute the callback?
define("name",["a","b","c"], function(a,b,c){
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…