How to add self executing function inside a constructor function

I create a constructor like

function foo (){
    this.bar=function(){
    //something
    };
}

this is fine till here but i wanna add inside a self executing function
that does something when i create this object with new keyword something might look like this

function foo(){
    (function(){
    //do something as soon as i create this object
    })();
    this.bar=function(){
    //something
    };
}

I want to run a self executing function when i create a new object . So how can i do something like i wrote above


Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.