ES7
class member syntax:ES7
has a solution for 'junking' your constructor function. Here is an example:
class Car {_x000D_
_x000D_
wheels = 4;_x000D_
weight = 100;_x000D_
_x000D_
}_x000D_
_x000D_
const car = new Car();_x000D_
console.log(car.wheels, car.weight);
_x000D_
The above example would look the following in ES6
:
class Car {_x000D_
_x000D_
constructor() {_x000D_
this.wheels = 4;_x000D_
this.weight = 100;_x000D_
}_x000D_
_x000D_
}_x000D_
_x000D_
const car = new Car();_x000D_
console.log(car.wheels, car.weight);
_x000D_
Be aware when using this that this syntax might not be supported by all browsers and might have to be transpiled an earlier version of JS.
function generateCar(wheels, weight) {_x000D_
_x000D_
class Car {_x000D_
_x000D_
constructor() {}_x000D_
_x000D_
wheels = wheels;_x000D_
weight = weight;_x000D_
_x000D_
}_x000D_
_x000D_
return new Car();_x000D_
_x000D_
}_x000D_
_x000D_
_x000D_
const car1 = generateCar(4, 50);_x000D_
const car2 = generateCar(6, 100);_x000D_
_x000D_
console.log(car1.wheels, car1.weight);_x000D_
console.log(car2.wheels, car2.weight);
_x000D_