niyazpk/Chess.js — comment on commit 68f872afe8767e76be4bdc7968cb306b54503cb3
File: scripts/chess.js line 37
By niyazpk:

Turns out this cannot be done so easily. The sample you provided will not work as such because in JavaScript objects you cannot include variables as keys in literal notation.

You will have to say:

```javascript
var PIECE_NAMES = {};

PIECE_NAMES[WHITE_KING] = 'WHITE_KING';
PIECE_NAMES[BLACK_QUEEN] = 'BLACK_QUEEN';
```

So instead, for now, I have modified the current function to *look* cleaner:

```javascript
function getPieceName(pieceValue){
switch (pieceValue) {
case WHITE_KING: return 'WHITE_KING';
case WHITE_QUEEN: return 'WHITE_QUEEN';
case WHITE_ROOK: return 'WHITE_ROOK';
}
}
```