In this code I dont understand this line
observer => observer.notify()
How it access another property in another class like that ?
class shopper_observer {
constructor(name) {
this.name = name;
}
notify(categoryName, discount) {
console.log(`${this.name}, there is a sale for ${categoryName} course. ${discount}% off`);
}
}
class Category_observable{
constructor(name) {
this.name = name;
this.subscribers = [];
}
subscribe(observer) {
this.subscribers.push(observer);
}
sale(discount) {
this.subscribers.forEach(observer => observer.notify(this.name, discount));
}
}
const designCategory = new Category_observable("Design Category");
const webCategory = new Category_observable("Web Dev Category");
const pdCategory = new Category_observable("Personal Dev Category");
const paul = new shopper_observer('Paul');
const mike = new shopper_observer('Mike');
const john = new shopper_observer('John');
const alex = new shopper_observer('Alex');
designCategory.subscribe(paul);
designCategory.subscribe(mike);
designCategory.subscribe(john);
webCategory.subscribe(mike);
pdCategory.subscribe(alex);
designCategory.sale(20);
webCategory.sale(15);
pdCategory.sale(25);