Self-invoking constructor pattern

by milostimotic

JavaScript

function Car (params) {
  if (!(this instanceof Car)) {
  	return new Car();
  }

  this.type = params.type;
  this.model = params.model;
  console.log('Type: ' + this.type + '; Model: ' + this.model + ';');
}

Car({type: 'SUV', model: 'BMW'});