参考http://www.feeldesignstudio.com/2013/09/javascript-module-pattern-basics
立即执行函数(IIFE Immediately-Invoked Function Expressions)
var name1 = function (){ console.log('name1') }();(function name2(){console.log('name2');})();
立即执行函数可以不暴漏私有变量
var myObject = (function(){var name = "FeeldesignStudio";return {getName : function(){return name;}}})();console.log(myObject.name);//undefinedconsole.log(myObject.getName());
让立即执行函数使用全局的变量和方法
var myHello=(function(o){function sayHello(){console.log('hello'+o.getName());}return {sayHi:sayHello}})(myObject);myHello.sayHi();