-2

私は3つのテキスト変数を持つJavascriptクラスを持っています:

myClasss = function(){
    this.color = "yellow";
    this.type = "car";
    this.other = this.type + ", " + this.color;
}

クラスにエラーがあります。どうすれば記入できthis.Otherますか?

4

1 に答える 1

0

関数の定義の後にセミコロンがないことを除けば、それは機能します。

myClasss = function() {
    this.color = "yellow";
    this.type = "car";
    this.other = this.type + ", " + this.color;
};
alert(new myClasss().other == "car, yellow");

あなたはjsFiddleでそれを見ることができます

于 2012-11-22T05:38:09.097 に答える