Dodá neutrálneho zástupcu namiesto prázdnej hodnoty, takže volanie nepadne.
class Discount { apply(amount) { throw new Error('abstraktná metóda'); }} class WinterDiscount extends Discount { apply(amount) { return amount * 0.8; }} // A neutral stand-in: it meets the interface, but does nothing.class NoDiscount extends Discount { apply(amount) { return amount; }} class Cart { constructor(discount) { this.discount = discount; } total(amount) { // No check for an empty value — there is nothing to check. return this.discount.apply(amount); }} const withDiscount = new Cart(new WinterDiscount());const withoutDiscount = new Cart(new NoDiscount()); withDiscount.total(100); // 80withoutDiscount.total(100); // 100