1

Possible Duplicate:
Self-references in object literal declarations

Given this object:

var OBJ = (function(){

    var dom = {
            prop1 : 'something',
            prop2 : 'something',
            prop3 : prop1
        }

    return dom.prop3;

})();

How would i go to achieve the prop3 reference (ideally without creating a method) ? i tried:

this.prop1, dom.prop1, this.dom.prop1

Community
  • 1
  • 1
silkAdmin
  • 4,640
  • 10
  • 52
  • 83
  • 3
    Technically, you can't do this... You need to assign prop3 value after initializing dom object. `dom.prop3 = dom.prop1;` – Ketan Modi Aug 06 '12 at 08:20

1 Answers1

7

You can't access the properties of an object before you have finished creating it. Create the object, then assign additional values.

var dom = {
        prop1 : 'something',
        prop2 : 'something'
};
dom.prop3 = dom.prop1;
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335