2016-03-20 8 views
-1

私はスパイダーモンキーを使って簡単なコンソールチェスゲームを作っています。 しかし、私はエラーSyntaxError: missing : after property id:を私の列挙宣言に入れ続けています。Javascript SpiderMonkey SyntaxError:missing:afterプロパティid:

相続人
SyntaxError: missing : after property id: 
ChessPiece.js:4:5  var Color = { 
ChessPiece.js:4:5 ............^ 

完全なコード

class ChessPiece 
{ 
    var Color = { 
     WHITE : 'W', 
     BLACK : 'B' 
    }; 

    var Piece = { 
     PAWN : 'P', 
     ROOK : 'R', 
     KNIGHT : 'N', 
     BISHOP : 'B', 
     QUEEN : 'Q', 
     KING : 'K' 
    }; 

    constructor(color, piece) 
    { 
     this.color = color; 
     this.piece = piece; 
    } 

    toString() 
    { 
     return this.color + this.piece; 
    } 
} 

編集します。var宣言として列挙型の構文を更新しました。

+0

JavaScriptのエンジンでは無効です。 –

+0

@JaromandaX有効ではないのはどうですか?あなたは明確にすることができますか? – 0x0byte

+0

構文 - enumは予約語ですが、使用方法を示すドキュメント(MDN、ES2015)が見つかりません...修正[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Future_reserved_keywords)は*将来の予約キーワードとして文書化します* –

答えて

0

私はクラス本体の中でenumを定義することはできないと思います。クラス定義の後に追加することができました。

class ChessPiece 
{ 
    constructor(color, piece) 
    { 
     this.color = color; 
     this.piece = piece; 
    } 

    toString() 
    { 
     return this.color + this.piece; 
    } 
} 

ChessPiece.Color = { 
    WHITE : 'W', 
    BLACK : 'B' 
}; 

ChessPiece.Piece = { 
    PAWN : 'P', 
    ROOK : 'R', 
    KNIGHT : 'N', 
    BISHOP : 'B', 
    QUEEN : 'Q', 
    KING : 'K' 
}; 
関連する問題