A shim to make make Node GRPC bindings more JavaScript-y This function allows me to write this code

const audioOutConfig = new AudioOutConfig();
audioOutConfig.setSampleRateHertz(16000);
audioOutConfig.setEncoding(AudioOutConfig.Encoding.LINEAR16);
audioOutConfig.setVolumePercentage(100);


as this code

const audioOutConfig = config(new AudioOutConfig(), {
  sampleRateHertz: 16000,
  encoding: AudioOutConfig.Encoding.LINEAR16,
  volumePercentage: 100
});


Is this a bad idea, and is the function I wrote to do it acceptable?

function config(obj, opts) {
  for (var opt in opts) {
    if (opts.hasOwnProperty(opt)) {
      obj[`set${opt.charAt(0).toUpperCase() + opt.slice(1)}`](opts[opt]);
    }
  }
  return obj;
}
Both the idea and implementation look sound to me. As a nitpick, you might consider using a reduce on the opts, giving you a one liner. Also, I believe the hasOwnProperty test is superfluous here

Untested reduce version

Note that, per Joseph's suggestion, which I agree with, this creates the AudioOutConfig object for you, rather than requiring it as a parameter:

function config(opts) {
  return Object.keys(opts).reduce((audio, opt) =&gt; {
    const methodName = `set${opt.charAt(0).toUpperCase() + opt.slice(1)}`
    return audio[methodName] ?  audio[methodName](opts[opt]) : audio
  }, new AudioOutConfig())
}