我有以下功能
var myInstance = (function() { var privateVar = 'Test'; function privateMethod () { // ... } return { // public interface publicMethod1: function () { // all private members are accesible here alert(privateVar); },publicMethod2: function () { } }; })();
如果我在函数中添加新内容,会有什么不同.从萤火虫看来,似乎两个物体是相同的.据我了解,两者都应该强制执行单身模式.
var myInstance = new (function() { var privateVar = 'Test'; function privateMethod () { // ... } return { // public interface publicMethod1: function () { // all private members are accesible here alert(privateVar); },publicMethod2: function () { } }; })();