除了可维护性外,第一种方法消除了意外事故全局变量创建的可能性:(function () {var variable1 = "Hello World!" // semicolon is missed out accidentlyvar variable2 = "Testing..."; // still a local variablevar variable3 = 42;}());而第二种方式则不那么宽容:(function () {var variable1 = "Hello World!" // comma is missed out accidently variable2 = "Testing...", // becomes a global variable variable3 = 42; // a global variable as well}());