Skip to content

Instantly share code, notes, and snippets.

@davidrhyswhite
Last active August 25, 2016 22:43
Show Gist options
  • Save davidrhyswhite/e4270eb631cd250654b57268c5ce3a52 to your computer and use it in GitHub Desktop.
Save davidrhyswhite/e4270eb631cd250654b57268c5ce3a52 to your computer and use it in GitHub Desktop.
For the Medium article on Object.defineProperty
class FinancialYear {
constructor(turnover, costOfGoods) {
this.turnover = turnover;
this.costOfGoods = costOfGoods;
Object.defineProperty(this, 'grossProfitMargin', {
get () {
const gpm = ((this.turnover - this.costOfGoods) / this.turnover) * 100;
return `${gpm}%`;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment