Possible Duplicate:
Difference between (function(){})(); and function(){}();
I am trying to understand a few of the features of JavaScript a little better. In The Definitive JavaScript
it says that self-executing functions should have brackets round them like so:
var obj = (function() {
var value = 0;
return {
increment: function(inc) {
value += typeof inc === "number" ? inc : 1;
},
getValue: function() {
return value;
}
}
})();
but in JavaScript - The Good Parts
where this example is taken from, it has the above self-executing function without the brackets round, like so:
var obj = function() {
var value = 0;
return {
increment: function(inc) {
value += typeof inc === "number" ? inc : 1;
},
getValue: function() {
return value;
}
}
}();
Both of these examples work for me, but I wanted to ask if there were any differences in functionality that I should be aware of. I hope this isn't too trivial. I just wanted to be sure.
Thanks a lot.
Edit:
As Rob W has pointed out, there is another thread on the subject. This is an excellent blog regarding this issue that was linked to from the other post.