I'm trying to implement the Singleton pattern via iffes and closures. i managed to so but was wandering if there is a difference between both ways (counter and counter2) of using the parentheses.
would love to understand the difference of using parentheses () for invoking the function expression is contained inside the outer parentheses vs using parentheses () for invoking the function expression is outside the wrapping parentheses for the function expression.
var counter = (function sequenceIIFE() {
var current = 0;
return {
getCurrentValue: function() {
return current;
},
getNextValue: function() {
current = current + 1;
return current;
}
};
})();
var counter2 = (function sequenceIIFE() {
var current = 0;
return {
getCurrentValue: function() {
return current;
},
getNextValue: function() {
current = current + 1;
return current;
}
};
}());
console.log(counter.getNextValue());
console.log(counter.getNextValue());
console.log(counter2.getNextValue());
console.log(counter2.getNextValue());