Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:59:18+00:00 2026-06-18T12:59:18+00:00

This works, but does any have a suggestion for a more simplified / elegant

  • 0

This works, but does any have a suggestion for a more simplified / elegant way to write this?:

if @mediaAddQueue[''+mid]['mediaType'] is 'photo' and
  @mediaAddQueue[''+mid]['econ_status'] is 'loaded' and
  @mediaAddQueue[''+mid]['medium_status'] is 'loaded' and
  @mediaAddQueue[''+mid]['thumb_status'] is 'loaded' and
  not @mediaAddQueue[''+mid]['targetEventRecord']?
    @addMedia @mediaAddQueue[''+mid]['targetEventRecord'], mid, @mediaAddQueue[''+mid]['mediaType']
else if @mediaAddQueue[''+mid]['mediaType'] is 'video' and
  @mediaAddQueue[''+mid]['video_status'] is 'loaded' and
  not @mediaAddQueue[''+mid]['targetEventRecord']?
    @addMedia @mediaAddQueue[''+mid]['targetEventRecord'], mid, @mediaAddQueue[''+mid]['mediaType']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:59:19+00:00Added an answer on June 18, 2026 at 12:59 pm

    Sure! First, notice that @mediaAddQueue[''+mid] is repeated all over the place, you can replace that with a variable. Also, there’s no need to access properties like something['prop'] if the property has a valid identifier as a name; you can do something.prop. Changing those two things already cleans the code quite a bit:

    media = @mediaAddQueue[mid]
    
    if media.mediaType is 'photo' and
      media.econ_status is 'loaded' and
      media.medium_status is 'loaded' and
      media.thumb_status is 'loaded' and
      not media.targetEventRecord?
        @addMedia media.targetEventRecord, mid, media.mediaType
    else if media.mediaType is 'video' and
      media.video_status is 'loaded' and
      not media.targetEventRecord?
        @addMedia media.targetEventRecord, mid, media.mediaType
    

    Then, notice that the code inside both the if and the else if is the same. I think it would be great if you could give some meaningful name to the conditions so that the code becomes more self-documented and DRY. I don’t know much about the context of this code, so i’ll be guessing the variable names; try to use something that explains their meaning as clearly as possible:

    media = @mediaAddQueue[mid]
    
    isValidPhoto = media.mediaType is 'photo' and
      media.econ_status is 'loaded' and
      media.medium_status is 'loaded' and
      media.thumb_status is 'loaded' and
      not media.targetEventRecord?
    
    isValidVideo = media.mediaType is 'video' and
      media.video_status is 'loaded' and
      not media.targetEventRecord?
    
    if isValidPhoto or isValidVideo
      @addMedia media.targetEventRecord, mid, media.mediaType
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have write this code but it does work only if I am already
This works printf(%s body\n,__PRETTY_FUNCTION__); But this does not (Error Expected ')' ): printf(__PRETTY_FUNCTION__ body\n);
This works in Firefox and Chrome, but fails in IE. It does show results
My Apache server works fine without -DSSL, but does not start with SSL. This
This javascript code does not work in IE8, but works in Firefox and Google
I tried this here: http://jsfiddle.net/92HXT/1/ but it does not work. It only works if
I have tried this but it does not work (even if I specify .wav
Seeking a more elegant solution I have this piece of code, I just use
I know dbsight allows synonyms and stop words for searching but does this take
This piece of code used to work in MVC 1 but it does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.