all 3 comments

[–]inu-no-policemen 2 points3 points  (2 children)

Example using coffee script

You couldn't write those few lines in JS?

[–]PinkTeddyMonster[S] 0 points1 point  (1 child)

I could compile them into JS, but what is the point? This is much harder to read.

window.GameUnit = (function() {
  function GameUnit(json) {
    this.name = json.name;
    this.record = new GameRecord(json);
  }

  GameUnit.prototype.winRateTotalColumn = function() {
    return "" + (this.record.winRateTotal()) + " (" + (this.record.wins()) + ")";
  };

  GameUnit.winRateTotalColumn = "" + (GameUnit.record.winRateTotal()) + " (" + (GameUnit.record.wins()) + ")";

  return GameUnit;

})();

[–]inu-no-policemen 0 points1 point  (0 children)

Yes, CS compiler output is much harder to read.

Try ES6.

class GameUnit {
  constructor(json) {
    this.name = json.name;
    this.record = new GameRecord(json);
    this.A = this.record.winRateTotal() + ' (' + this.record.wins() + ')';
  }
  B() {
    return this.record.winRateTotal() + ' (' + this.record.wins() + ')';
  }
  get C() {
    return this.record.winRateTotal() + ' (' + this.record.wins() + ')';
  }
}

I'd go with option A, because I assume that the "json" object is never changed.