A JavaScript class provides a familiar way to define objects and model inheritance. It streamlines prototype configuration, especially for domain models, without replacing JavaScript’s prototype-based object system. section 2.3 section 2.4
Unlike class-based models that copy inherited properties into instances, JavaScript links objects through prototypes. Classes make inheritance hierarchies easier to express, but can obscure how those links work. section 2.3 section 2.4
Choose classes with their tradeoffs in mind:
- They reduce the boilerplate of constructor functions and prototype setup. section 2.3
- They are useful for inheritance-based modeling, but are not the only way to build objects or practice object-oriented programming. section 2.3 section 2.4
class Transaction {
constructor(sender, recipient, funds = 0.0) {
this.sender = sender;
this.recipient = recipient;
this.funds = Number(funds);
}
displayTransaction() {
return `Transaction from ${this.sender} to ${this.recipient}
for ${this.funds}`;
}
}
A Transaction class uses a constructor to initialize instance data and a method to format a transaction. section 2.3




















