Question

I'm not sure if this is possible, or if I'm taking the wrong approach, I've tried searching, but I'm not sure about the terms.

I would like to pass a variable into the controller dict, so rather than using 'PLAY', in the lookup I could do something like controller('OPTION','PLAY')

var ip = '192.168.1.5'
var Keys = {
            HOME:          '/keypress/Home',
            REV:           '/keypress/Rev',
            FWD:           '/keypress/Fwd',
            PLAY:          '/keypress/Play',
            SELECT:        '/keypress/Select',
            LEFT:          '/keypress/Left',
            RIGHT:         '/keypress/Right',
            DOWN:          '/keypress/Down',
            UP:            '/keypress/Up',
            BACK:          '/keypress/Back',
            INSTANTREPLAY: '/keypress/InstantReplay',
            INFO:          '/keypress/Info',
            BACKSPACE:     '/keypress/Backspace',
            SEARCH:        '/keypress/Search',
            ENTER:         '/keypress/Enter',
            A:             '/keypress/Lit_a'
     }

from this:

var controller = {
                  PLAY:{
                        hostname: ip,
                        port: 8060,
                        path: Keys['PLAY'],
                        method: 'POST'
                        }
                  }

to this:

var controller = {
                  OPTION:{
                        hostname: ip,
                        port: 8060,
                        path: Keys[Key],
                        method: 'POST'
                        }
                  }

I'm trying to avoid the following

var controller = {
                  PLAY:{
                        hostname: ip,
                        port: 8060,
                        path: Keys['PLAY'],
                        method: 'POST'
                        }
                  FWD :{
                        hostname: ip,
                        port: 8060,
                        path: Keys['FWD'],
                        method: 'POST'
                        }
                  REV :{
                        hostname: ip,
                        port: 8060,
                        path: Keys['REV'],
                        method: 'POST'
                        }
                  ...

                  }
Was it helpful?

Solution

Were you thinking of something like this:

controller = {
       OPTION : function(key){
                    return {
                    hostname: ip,
                    port: 8060,
                    path: Keys[key],
                    method: 'POST'
                   } 
                   }
              }

then you could get it with controller.OPTION("PLAY"). It is essentially creating the getOption() method epascerallo suggested just coupled into the controller object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top