2011-07-08 1 views
0

私はオンラインチュートリアルに従っています。私はプロトタイプセクションにあります。私のalertにはJavaScriptプロトタイピングが動作しない

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

答えて

3

s.fullNameは関数そのものです。この関数を呼び出す場合は、s.fullName()を記述する必要があります。

+0

ええ、あなたは関数ではなくプロパティを呼び出しています。すべての関数はwith()= bracesと呼びます。オハイオ州の権利を – marko

+0

haha​​。ありがとうございます。回答は –

+0

です@marko:かっこ。中括弧は '{}'です。 – katspaugh

関連する問題