1

Possible Duplicate:
Are “(function ( ) { } ) ( )” and “(function ( ) { } ( ) )” functionally equal in JavaScript?

Is there a difference between these two?

(function () {}());

and

(function () {})();

What do you think about this for building objects within a global:

;(function () {
            'use strict';

            this.menu = (function () {
                var version = "1.2.111",
                    someFunction = function() {
                        console.log("Version: " + version);
                        return version;
                    };
                return {
                    getVersion: someFunction
                };
            })();

            this.someObject = (function () {
                var privateVar = "1234",
                    privateFunction = function () {
                        console.log("Private Variable: " + privateVar);
                        return privateVar;
                    };

                return {
                    publicFunction: privateFunction
                };
            })();

        }).apply(window.saif = window.saif || {});
Community
  • 1
  • 1
Sam
  • 15,336
  • 25
  • 85
  • 148
  • 1
    This is a really good question, I've been wondering the same thing for quite a while now... One thing I have noticed is that the variable scope changes between the two, I just can't precisely explain how they change... (I noticed I couldn't access some variables/functions within the (function(){})() method, in which I normally would in regular functions. – sergiocruz Nov 02 '12 at 19:35
  • 2
    @sergiocruz: The variable scope will be the same for either syntax. If you noticed a change in the `this` value of a function, it wouldn't be because of a difference between the two examples at the top. – I Hate Lazy Nov 02 '12 at 19:38

0 Answers0