Search code examples
javascriptprototype-programming

JavaScript prototyping not working


I am following an online tutorial and I am at a prototype section. My alert comes back with

function() { return this.brand + ' ' + this.model; }

Anyone know the reason?

function Car(model, brand) {
    this.model = model;
    this.brand = brand;
}

Car.prototype.fullName = function() {
    return this.brand + ' ' + this.model;
}

var s = new Car("G5", "Pontiac");
var full = s.fullName;
alert(full);

Solution

  • s.fullName is the function itself. If you wanted to call this function you would have to write s.fullName().