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

Posted by Kucebe on Stack Overflow See other posts from Stack Overflow or by Kucebe
Published on 2010-05-15T15:29:20Z Indexed on 2010/05/15 15:34 UTC
Read the original article Hit count: 162

Filed under:
|
|

I'd like to initialize an object in javascript calling directly a method that belongs to it:

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

  //later
  obj.uninit();
  obj.init();

This specific example doesn't work, is there something similar?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about initialization