Access JavaScript Object Literal value in same object [duplicate]

Possible Duplicate:
Self-references in object literal declarations

Is there any way access the value of a property name in the same object literal? Something like this:

    varOne: 'something',
    varTwo: this.varOne + 'something else'

No, there is no way to access the object literal that is currently being defined from within the definition itself.

If you want to set properties based on the values of other properties, then you either need to base them both on some external value (that is not a property itself) or run an initializer function after the object literal is defined that can set some properties based on the values of other properties.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   When to use node.js vs sinatra vs rails? [closed]

Similar Posts