1

Is it possible to set one object's key $thumbnailContainer to the value of another object thumbnailImg within the same object gallerySelectors?

Example:

var gallerySelectors = {
    '$thumbnailContainer' : $('#thumb'),
    'thumbnailImg' : this.$thumbnailContainer.find('img')
};

2 Answers 2

1

No, unfortunately, there isn't. Luckily, the alternative is just as simple:

var gallerySelectors = {
    $thumbnailContainer: $('#thumb')
};

gallerySelectors.thumbnailImg = gallerySelectors.$thumbnailContainer.find('img');

You could also make a function to do that for you if the issue is that you want to pass the object inline.

Sign up to request clarification or add additional context in comments.

Comments

0

No, because this will not be bound to the object in the situation you show.

I don't think there is a way to do this.

You could try

var gallerySelectors = {
    '$thumbnailContainer' : $('#thumb'),
    'thumbnailImg' : gallerySelectors.$thumbnailContainer.find('img')
};                     ^--------------- NOTE!!!

but I'm not sure whether I would trust this to work everywhere. I guess you'd have to look into the language spec to see whether the members are always guaranteed to be initialized in order.

I would just take the easy route:

var gallerySelectors = {
    '$thumbnailContainer' : $('#thumb'),
    'thumbnailImg' : $('#thumb').find('img')
};

2 Comments

I'm sure you didn't mean to type this: $('#thumb').$thumbnailContainer.find('img')
Bummer. Thanks anyway. This is the method that I was probably going to end up doing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.