以下のコンストラクター関数に名前と色を送ってみます。メソッドthis.whatAreYou()
は、呼び出されたときにこれらの文字列を取得する必要があります。
これを画面に表示したい。
私は次のコードを持っています:
function Gadget(name, color) {
this.name = name;
this.color = color;
this.whatAreYou = function() {
return 'I am a ' + this.name+ ' ' + this.color;
};
}
string = Gadget(grass, green);
alert(string);
ただし、アラートは機能していません。どうすれば希望の動作を実現できますか?