狐七的面试题库

整理,永远在路上~

vuePress-theme-reco 狐七    2022 - 2024
狐七的面试题库 狐七的面试题库

Choose mode

  • dark
  • auto
  • light
Home
计算机基础
  • 计算机网络
  • 垃圾回收
前端基础
  • 浏览器
  • 前端基础

    • html
    • css
    • js
前端工程化和框架
  • 前端工程化

    • 前端工程化
  • 前端框架

    • Vue
    • React
前端编程题
  • 编程题
  • 代码题
后端
  • php
  • goLang
  • 架构
  • Redis
  • MySQL
  • Linux
  • Nginx
  • Docker
  • Java
算法和数据结构
  • 数据结构
  • 算法
TimeLine
author-avatar

狐七

76

Articles

14

Tags

    Home
    计算机基础
    • 计算机网络
    • 垃圾回收
    前端基础
    • 浏览器
    • 前端基础

      • html
      • css
      • js
    前端工程化和框架
    • 前端工程化

      • 前端工程化
    • 前端框架

      • Vue
      • React
    前端编程题
    • 编程题
    • 代码题
    后端
    • php
    • goLang
    • 架构
    • Redis
    • MySQL
    • Linux
    • Nginx
    • Docker
    • Java
    算法和数据结构
    • 数据结构
    • 算法
    TimeLine
    • programming

      • 实现数组方法
      • Promise方法实现
      • 函数方法实现
      • ES6语法的Babel解析
      • 面向对象实现
      • 设计模式实现
      • Vue原理实现
      • 正则表达式
      • 函数深拷贝写法

    设计模式实现

    vuePress-theme-reco 狐七    2022 - 2024

    设计模式实现

    狐七 3/14/2022 programming

    • 发布订阅模式

    # 发布订阅模式

    Class Notify {
        constructor() {
            this.subscribers = []
        }
        add(handler) {
            this.subscribers.push(handler)
        }
        emit() {
            this.subscribers.forEach(subscriber => subscriber())
        }
    }
    
    let notify = new Notify()
    // 收集依赖
    notify.add(() => {
        console.log('emit here');
    })
    
    // 执行任务
    notify.emit()
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    更新时间: 2022-03-31 02:04

    面向对象实现 Vue原理实现

    • 发布订阅模式