LOCKING盒子版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

17 lines
322 B

  1. class Subject {
  2. constructor() {
  3. this.observers = [];
  4. }
  5. add(observer) {
  6. this.observers.push(observer);
  7. }
  8. remove(observer) {
  9. this.observers = this.observers.filter((iO) => iO !== observer);
  10. }
  11. notify(...args) {
  12. this.observers.forEach((f) => f(...args));
  13. }
  14. }
  15. module.exports.Subject = Subject;