设计模式
Time202051
这个作者很懒,什么都没留下…
展开
-
js代理模式
// 用户支付的租金 class Money { constructor(money) { this.money = money } } // 租客 源对象 class User { constructor(name, money, target) { this.name = name this.money = money this.target = target } // 付钱 payMone原创 2021-08-12 17:38:49 · 57 阅读 · 0 评论 -
观察者模式
// 主题 报社 class Subject { constructor(name) { this.name = name this.news = "" //报社发布的内容,将会发布给所有已订阅报纸的用户 this.observers = [] //用户数组 } add(observer) { this.observers.push(observer) } getState() { re原创 2021-08-12 12:54:10 · 59 阅读 · 0 评论 -
js单例模式
class LoginForm { constructor() { this.state = 'hide' } show() { if (this.state == "show") { return } this.state = 'show' console.log("登录框显示"); } hide() { if (this.state === 'h原创 2021-08-12 15:56:36 · 64 阅读 · 0 评论