Implementing the Observer pattern in JavaScript