Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Last active January 5, 2020 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbmilgrom/f23a53c630bce4ec5d279a20bc9e5f85 to your computer and use it in GitHub Desktop.
Save jbmilgrom/f23a53c630bce4ec5d279a20bc9e5f85 to your computer and use it in GitHub Desktop.
Highlight assignment of variable in class construction
class BankAccount {
private balance;
constructor(funds) {
this.balance = funds;
}
public withdraw(amount) {
this.balance = this.balance - amount; // <-- assign `this.balance` a new value
}
public checkBalance() {
return this.balance;
}
}
const bankAccount = new BankAccount(100);
bankAccount.withdraw(20);
bankAccount.checkBalance(); // 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment