0

How to correctly do something like this in JavaScript ?

var object = 
{
   variable1: "test",
   variable2: "sec test",
   variable3 : variable2
}

Is this correct aproach ?

I have created solution like this but I dont know is this good. I am programming newbie. This is JavaScript using jQuery JavaScript library:

(function($, window, document, undefined){

var sakrijContent = 
{

    container : $("div#content"),
    clickCont : $("div#content").find("h3").first(),
    hideBody: "",

    init: function()
    {

        this.hideBody = this.container.find("ul.lista1").first();
        this.clickCont.on("click", function(){

               sakrijContent.hideBody.slideToggle();
        });
    }





}

   sakrijContent.init();


})(jQuery, window, document);
Sysrq147
  • 1,359
  • 4
  • 27
  • 49
  • possible duplicate of [Self-references in object literal declarations](http://stackoverflow.com/questions/4616202/self-references-in-object-literal-declarations) – Matt Ball Nov 12 '13 at 21:54

1 Answers1

1

The simple solution would be:

var var2 = "sec test";
var object = {
   variable1: "test",
   variable2: var2,
   variable3: var2
};
Russell Zahniser
  • 16,188
  • 39
  • 30