[quote=“felgall, post:31, topic:223000, full:true”]
Yes, this particular situation is one of the few where there isn’t a better way.[/quote]
Why are IIFE’s not a better way? Let’s compare the two:
Functions that reach out and change external variables.
var removeEvent;
var addEvent = function (...) {
// using lazy evaluation
...
addEvent = function (...) {
...
};
removeEvent = function (...) {
...
};
addEvent(...);
};
Compared with using IIFE’s to return the appropriate function:
var addEvent = (function () {
// invoked immediately
...
return function (...) {
...
};
}());
var removeEvent = (function () {
// invoked immediately
...
return function (...) {
...
};
}());
Are there reasons why IIFE’s are not a better technique to use for this type of situation?