oop-constructor

by Shridhar Baddur

JavaScript

'use strict';

var Car = function(_color) {
	if(!new.target) throw "Car() should be called with new";
	
	this.setColor = function(color) {
		_color = color;
	};
	this.getColor = function() {
		return _color;
	};
};
var redCar = new Car('red');

console.log(redCar.getColor());