0

I am using ES6 and Babel, I would like to know if there is a more concise way to rewrite the following function using rest/spread operators.

And how to set babel preset for that. Thanks guys.

 init(fields, file, res, req) {
    // I want the following mapping done automatically
    this.fields = fields;
    this.file = file;
    this.res = res;
    this.req = req;
},
Radex
  • 7,815
  • 23
  • 54
  • 86
  • There are no rest/spread operators. There are [*rest parameters/syntax*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) and [*spread syntax*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator). – RobG Apr 05 '17 at 08:23
  • 1
    The duplicate should answer the question, replacing the object name with `this`, e.g. `Object.assign(this, { fields, file, res, req });` – CodingIntrigue Apr 05 '17 at 08:27
  • would be possible using es7 an babel presets? – Radex Apr 05 '17 at 08:29

0 Answers0