reference variable in object literal? [duplicate]

You could make var3 a function, and calling it will allow you to use ‘this’:

x= {
    v1:4,
    v2:5,
    v3:function(){return this.v1 + this.v2;}
};

alert(x.v3());

Leave a Comment