john chambers
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER