Link to home
Start Free TrialLog in
Avatar of john chambers
john chambersFlag 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

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of john chambers

ASKER

Cool, exactly what I was looking for. Thanks.