I tried hard to understand the code inside for loop, but i couldn't achieve anything. This program outputs A-Z (As an exercise)
Question:
Why is there an IIFE inside that loop. why removing it doesn't work. what's it's role.
Oh, Damn it, I have lot's of questions about this loop and why it works. I tried with debugging, but no outcome as a teaching material out of it. Can someone please explain it? Like stacking and so one.
debugger;
(function(global){
function C() {
console.log("OOPS!");
}
function E(f) {
console.log("E");
f();
var f = F;
}
var A = function() {
console.log("A");
B();
};
var C;
function G() {
console.log("G");
H();
function H() {
console.log("H");
I();
}
}
var D = d;
function d() {
console.log("D");
E(F);
}
function I() {
console.log("I");
J();
J();
}
var B = function() {
console.log("B");
C();
};
var F = function() {
console.log("F");
G();
};
obj = {};
var rest = "KLMNOPQRSTUVWXYZ".split("");
for (var i=0; i<rest.length; i++) {
(function(i){
// define the current function
obj[rest[i]] = function() {
console.log(rest[i]);
if (i < (rest.length-1)) {
obj[rest[i+1]]();
}
};
})(i);
}
var J = function() {
J = function() {
console.log("J");
obj.K();
};
};
function C() {
console.log("C");
D();
}
return A;
})(window)();