0

I have an object which is a list of filters corresponding to a select list. When the user selects from a drop-down I want update the object using this getter/setter. I'm also using an event listener. I thought the argument would be automatically passed into the handler.

var formFilters = {
  audience: 'All',
  get audienceFilter() {
    return this.audience;
  },
  set audienceFilter(input) {
    $('select').on('change', this.audienceFilter);
  }
};

Then to see what's going on:

$('select').on('change', function(e){
  console.log(formFilters.audience);
});
icicleking
  • 1,029
  • 14
  • 38

1 Answers1

1

It is pretty straigth forward actually:

formFilters.audienceFilter = 'customValue';

Update: https://jsfiddle.net/7431fz7u/1/

Hackerman
  • 12,139
  • 2
  • 34
  • 45
  • The thing I'm struggling with is how to pass the select element's value to the setter. `$('select').on('change', formFilters.audienceFilter)` doesn't appear to work – icicleking May 19 '16 at 18:53