Possible Duplicate:
Self-references in object literal declarations
How do I do the following:
var object = {
alpha: 'one',
beta: **alpha's value**
}
without splitting the object creation into two parts?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t, object literal syntax just doesn’t support this, you’ll have to create a variable first then use it for both, like this:
Or…something entirely different, but you can’t reference
alphawhen doingbeta, because neither property has been created yet, not until the object statement runs as a whole is either accessible.