Is possible to initialize an object in javascript in this way? -


I would like to start an object directly in JavaScript in a method that comes under it:

  var obj = (function () {return} init: function () {console.log ("initialized!"); Return it;}, uninit: function (x) {console.log ("uninitialized!") ;           }       };   }).in this(); // later obj.uninit (); Obj.init ();  

This specific example does not work, is there something similar?

Edit: init () returns this Thanksgiving Cave

You are defining only an anonymous function, but are not actually calling it. To call it immediately, add a pair of parentheses:

  var obj = (function () {return {init: function () {console.log ("initialized!");; }, Uninit: function (x) {console.log ("uninitialized!");}};}) () Init ();  

Comments