on() event handler for multiple objects I'm using three instances of ace editor in a form. I initialize them like so:

var before = ace.edit("beforeSQL", {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
}),
execute = ace.edit("executeSQL", {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
}),
after = ace.edit("afterSQL", {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
});


I then put a listener on each one to make sure there's content in each field before the user can click the submit button:

  before.session.on('change', () =&gt; {
    toggleSubmit();
  });
  execute.session.on('change', () =&gt; {
    toggleSubmit();
  });
  after.session.on('change', () =&gt; {
    toggleSubmit();
  });


The toggleSubmit() function enables the submit button when each editor stores a value. 

Both sections of code feel redundant, but the second section is what really concerns me. Anyone know a clever way to whittle this down? For example is there a way I could do the following:

[before.session, execute.session, after.session].on('change', () =&gt; {
  toggleSubmit();
});
var before = ace.edit("beforeSQL", {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
}),
execute = ace.edit("executeSQL", {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
}),
after = ace.edit("afterSQL", {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
});


There's a lot of repetition here in terms of the options you're using. You could avoid repeating yourself by creating an object to hold defaults. For example:

const defaults = {
  showPrintMargin: false,
  fontSize: '14px',
  theme: "ace/theme/sqlserver",
  mode: "ace/mode/sql" 
}

var before = ace.edit("beforeSQL", {...defaults})
var execute = ace.edit("executeSQL", {...defaults})
var after = ace.edit("afterSQL", {...defaults})


To avoid repeating yourself when adding an event listener you could do something like this:

[before, execute, after].forEach(obj =&gt; {
  obj.session.on('change', toggleSubmit);
})