troubleshooting Question

Wanting to use javascript static class instead of switch statement.

Avatar of john chambers
john chambersFlag for United States of America asked on
JavaScript
2 Comments1 Solution323 ViewsLast Modified:
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';
    }
};
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros