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);
});
1
  • 2
    It's not clear to me what the problem is, or what you think the code above should be doing. Commented May 19, 2016 at 18:35

1 Answer 1

1

It is pretty straigth forward actually:

formFilters.audienceFilter = 'customValue';

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.