Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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:

myFunction.init({
    varOne: 'something',
    varTwo: this.varOne + 'something else'
})
share|improve this question
add comment

marked as duplicate by Felix Kling, kapa, Wh1T3h4Ck5, xdazz, Peter O. Oct 13 '12 at 5:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
Ok, thank you very much for the quick response! I'll have to create an external variable and access that within the object. –  Adrian Florescu Sep 30 '12 at 8:31
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.