user450549
user450549

Reputation:

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);

Upvotes: 0

Views: 62

Answers (1)

Ray Toal
Ray Toal

Reputation: 88408

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

Upvotes: 3

Related Questions