icicleking icicleking - 2 years ago 82
Javascript Question

How to pass arguments to setter in javascript object?

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){

Answer Source

It is pretty straigth forward actually:

formFilters.audienceFilter = 'customValue';

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download