CodeMirror.net uses this construct (I'm simplifying slightly) to introduce the code for its JavaScript editor:
(function(mod) {
this.CodeMirror = mod();
})(function() {
"use strict";
(15,000-odd lines of advanced JS)
}
Now, I understand that this is a self-executing function, and I've read a number of posts about them. I understand that, in practice, this code is creating a CodeMirror object. I just don't understand the mechanics.
- What is the role of the parameter (mod)? More broadly, what does it mean when you give a parameter to a self-executing function?
- What is the role of the inner function() declaration? It appears that this is related to mod in some way?
Thanks for your help.