I changed the last part of the question abit, as I found my mistake on the example I brought. Sorry for that.
While learning about JavaScript Module Pattern, as an example I saw code below:
var singletone1 = function() {
function sayHello() {
console.log("Hello")
}
return {
sayHello: sayHello
}
}()
This code works well as an example of revealing module pattern. But I realized that this makes the same result as IIFE version:
var singletone2 = (function() {
function sayHello() {
console.log("Hello")
}
return {
sayHello: sayHello
}
})()
The reason why I felt odd was that, as long as I know, running function declaration directly will make an error.
// Immediately Invoked Function Declaration
function(){
console.log('test');
}()
// => Uncaught SyntaxError: Unexpected token )
To run this, I have to embrace it with parenthesis. By that way, it becomes IIFE. But what is strange to me is the singletone1 example works as usual.
So my question is is there any difference on whether putting parenthesis between the function declaration or not? In other words, is there any difference between Revealing Module Pattern without parenthesis(singletone1) and IIFE version(singletone2)?
If they are same, then is that a matter of operator priority - so that the parenthesis are optional?