原型编程——JavaScript原型不能工作

prototype programming - JavaScript prototyping not working

本文关键字:原型 工作 不能 JavaScript 编程      更新时间:2023-09-26

我正在跟随一个在线教程,我在一个原型部分。我的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);

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