JavaScript原型设计不起作用

时间:2011-07-08 19:16:48

标签: javascript prototype-programming

我正在关注在线教程,我正处于原型部分。我的alert回来了

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

有人知道原因吗?

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 个答案:

答案 0 :(得分:3)

s.fullName是函数本身。如果你想调用这个函数,你必须写s.fullName()。