0

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

1 Answer 1

3

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

1
  • Yeah, you're calling the property not the function. All function should be called with () = braces.
    – marko
    Jul 8, 2011 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.