What are the pros and cons of utilizing Named IIFEs within JS code to describe and group related code?
I've been using this "pattern" to lend structure to my more procedural code that gets executed only in one place.
Example
(function hideStuffOnInstantiaton(){
$('oneThing').hide().removeClass();
$('#somethign_else').slideUp();
$('.foo').fadeOut();
}());
I find this preferable to both:
// hide Stuff on Instantiaton
$('oneThing').hide().removeClass();
$('#somethign_else').slideUp();
$('.foo').fadeOut();
since over time the comment may get separated from the code and its not immediately obvious what line(s) the comment applies to
and to:
function hideStuffOnInstantiaton(){
$('oneThing').hide().removeClass();
$('#somethign_else').slideUp();
$('.foo').fadeOut();
};
hideStuffOnInstantiaton();
becuase why separate the function and its execution if its only executed in one place?
Are there any performance, maintainability, testability, or cross-browser considerations when using this pattern? I don't believe I've seen many people use this in the wild butI feel as though it could be very useful
(function a(){ .. });
. I would perfer a comment instead. – Hydracid