I have some JS code here:
function Car(manufacturer, model, year) {
this.manufacturer = manufacturer;
this.model = model;
this.year = year == undefined ? new Date().getFullYear() : year;
this.getInfo = function(){
return this.manufacturer +' '+ this.model +' '+ this.year;
};
}
var bmw = new Car("BMW", "X5", 2010);
So I want some interesting output in the console:
console.log('Car: ' + bmw); // Car: BMW X5 2010
How to do it without calling any methods?
THANKS!
I need the 'getInfo' method, so I have simply changed my code:
function Car(manufacturer, model, year) {
this.manufacturer = manufacturer;
this.model = model;
this.year = year == undefined ? new Date().getFullYear() : year;
this.toString = this.getInfo = function(){
return this.manufacturer +' '+ this.model +' '+ this.year;
};
}
