Created
November 27, 2014 13:44
-
-
Save Partyschaum/25c9913456592b8b337c to your computer and use it in GitHub Desktop.
IIFE vs. plain function
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
function someFunction() { | |
// both methods do exactly the same thing. where is the difference then? | |
var reader = new FileReader(); | |
var img = document.createElement('img'); | |
// method A | |
reader.onload = (function(aImg) { | |
return function(e) { | |
aImg.src = e.target.result; | |
}; | |
})(img); | |
// method B | |
reader.onload = function(e) { | |
img.src = e.target.result; | |
} | |
reader.readAsDataURL(file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment