JavaScript自调用函数

时间:2012-11-02 19:31:53

标签: javascript self-invoking-function

  

可能重复:
  Are “(function ( ) { } ) ( )” and “(function ( ) { } ( ) )” functionally equal in JavaScript?

这两者之间有区别吗?

(function () {}());

(function () {})();

您如何看待在全局范围内构建对象:

;(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 || {});

0 个答案:

没有答案