Last active
January 5, 2017 11:47
-
-
Save gurucharanmk/38d8557147d2f542d553b75dfeb40709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var funcArray_1 = []; | |
var funcArray_2 = []; | |
//IIFE of type 1 | |
for (var i = 0; i < 10; i++) { | |
funcArray_1.push(function(val){ | |
return function() { console.log(val); } | |
}(i)); | |
} | |
console.log(i); // 10 | |
funcArray_1.forEach(function(func) { | |
func(); | |
}); | |
//IIFE of type 2 | |
for (var i = 0; i < 10; i++) { | |
(function(index){ | |
funcArray_2.push( | |
function(){ | |
console.log(index); | |
} | |
); | |
})(i); | |
} | |
console.log(i); // 10 | |
funcArray_2.forEach(function(func) { | |
func(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment