Skip to content

Instantly share code, notes, and snippets.

@Partyschaum
Created November 27, 2014 13:44
Show Gist options
  • Save Partyschaum/25c9913456592b8b337c to your computer and use it in GitHub Desktop.
Save Partyschaum/25c9913456592b8b337c to your computer and use it in GitHub Desktop.
IIFE vs. plain function
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