4
I am working on a project and using the standard Module Pattern javascript. But during the implementation of the project I had some doubts.
First doubt:
Is there any difference between the two ways of using the "Immediately-Invoked Function Expression (IIFE)"
var modulo = (function() {
//codigo
}());
var modulo = (function() {
//codigo
})();
Ben Alman, author of the article: Immediately-Invoked Function Expression (IIFE) implements in the first way.
Ja Addy Osmani, author of the book: Learning Javascript Design Patterns implements the second way.
I wonder if there is some kind of technical difference between these two forms. Or are they just two different ways to do the same thing?
2nd doubt:
I thought it would be interesting to add sub modules within my main module. But I looked at several examples and links related to the subject and found no approach using sub modules. Then I was in doubt, whether I should do it or not. The use of sub modules can cause me future problems or pollute my code?
Alan, there is no problem in creating a module within another, including what the
Vanilla Masker
does. when it comes to performance, recommendations and difference of execution in the IIFE calls, it does not exist, being only a matter of style, but the second mode is more common.– Tobias Mesquita
I was using the second form msm! thanks! ;)
– alan