Avatar of john chambers
john chambers
Flag for United States of America asked on

Wanting to use javascript static class instead of switch statement.

Hi all,

Hard to explain problem in the title, but basically I have a case statement right now that I'm using for MapQuest POI results to pull the facility type off of the POI returned.

So as you can see from the code snippet, I call result.getFacility() and I get a facility type.

I'd like to somehow get these values stored in a static variable somewhere if possible so that I could have a getFacility method that basically just returns something more like facilities[this.facility] (where facilities would be the static and this.facility is the code returned). It's possibly incredibly easy, I know how to do things like this in Rails/PHP but not JS so if anyone has ideas or alternate suggestions that would be awesome.  

Thanks!
Jen
this.getFacility = function(){
    switch(this.facility) {
        case '7011':
            return 'lodging';
        case '4581':
            return 'transporation';
        case '5800':
        case '2084':
        case '9996':
            return 'dining';
        case '7389':
        case '7990':
        case '5999':
            return 'other';
        default:
            return 'activities';
    }
};

Open in new window

JavaScript

Avatar of undefined
Last Comment
john chambers

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
john chambers

ASKER
Cool, exactly what I was looking for. Thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23