Javascript new object (function ) vs inline invocation

Posted by Sheldon Ross on Stack Overflow See other posts from Stack Overflow or by Sheldon Ross
Published on 2010-04-05T22:33:06Z Indexed on 2010/04/05 22:43 UTC
Read the original article Hit count: 286

Filed under:
|
|
|

Is there any considerations to determine which is better practice for creating an object with private members?

var object = new function () { 
   var private = "private variable";
   return {
       method : function () { 
           ..dosomething with private;
       }
   }
}

VS

var object = function () {
 ...
}();

Basically what is the difference between using NEW here, and just invoking the function immediately after we define it?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about private