当前位置: 首页 > news >正文

人才引进从事网站建设上海网站seoseodian

人才引进从事网站建设,上海网站seoseodian,网站百度权重怎么提升,wordpress网站图片加速2、观察者模式 2.1、观察者模式 2.1.1、前言 定义一种一对多的依赖关系,当一个对象发生变化时,所有依赖于它的对象都会自动收到通知并更新。 两个角色: Subject(主题/被观察者) Observer(观察者&…

2、观察者模式

2.1、观察者模式

2.1.1、前言

定义一种一对多的依赖关系,当一个对象发生变化时,所有依赖于它的对象都会自动收到通知并更新。

两个角色:

  1. Subject(主题/被观察者)
  1. Observer(观察者)

观察者模式一般至少有一个 Subject(主题) ,可以有多个Observer(观察者)。

二者关系: Subject(主题)主动建立与观察者的关系。

Subject(主题/被观察者):至少要有三个方法——添加观察者、移除观察者、通知观察者。

2.1.2、代码
		<input type="text" id="app" oninput="handleInput(event)">
<script>// 主题,接收状态变化,并通知每个观察者class Subject {constructor() {this.observers = []}// 新增观察者addObserver(observer) {this.observers.push(observer)}// 通知每个观察者notify(state) {this.observers.forEach(observer => {observer.update(state)})}removeObserver(observer) {const index = this.observers.indexOf(observer);if (index !== -1) {this.observers.splice(index, 1);}}}// 观察者,等待被通知class Observe {constructor(name) {this.name = name}update(state) {console.log(`${this.name} 获取到最新值:${state}`);}}const handleInput = (e) => {const event = e || eventconst value = event.target.value// 实例化一个主题const sub = new Subject()// 实例化两个观察者 一个沐歌,一个沐夏const muge = new Observe('沐歌')const muxi = new Observe('沐夏')// 添加观察者实例sub.addObserver(muge)sub.addObserver(muxia)// 状态改变,通知所有观察者sub.notify(value)}</script>

2.2、发布订阅模式

2.2.1、前言

发布订阅模式在观察者模式的基础上加入了 事件调度中心 ,提供更灵活的控制,适用于复杂的消息交互场景。

观察者模式是经典的设计模式,观察者和目标之间直接交互,适合简单的一对多通知。

2.2.1、代码
/** @Author: muge* @Date: 2021-05-21 18:46:09* @LastEditors: Please set LastEditors* @LastEditTime: 2023-03-09 16:37:47*/
//仿vue-$on $emit
class Event {// 首先定义一个事件对象,用来装事件数组(多个订阅者)handlers = {};// 订阅(事件添加方法) type=事件名 callback=回调函数$on(type, callback) {if (!this.handlers[type]) {// 没有则初始化this.handlers[type] = [];}// 存入该事件this.handlers[type].push(callback);}// 触发事件 type=事件名 params=参数$emit(type, params) {// 若没有注册该事件则抛出错误if (!this.handlers[type]) return new Error("未注册该事件");// 事件触发this.handlers[type].forEach((callback) => callback(params));}// 取消订阅 type=事件名 callback=回调函数$unsubscribe(type, callback) {// 无效事件抛出异常if (!this.handlers[type]) return new Error("未注册该事件");// 执行回调callback&&callback()// 删除事件delete this.handlers[type];}
}
// 创建一个event实例
const sub = new Event();
// 订阅事件changeInputValue onLaod
sub.$on("changeInputValue", (params) => {console.log("params", params);
});
sub.$on("onLaod", (params) => {console.log("params", params);});
console.log('当前的事件列表',sub.handlers);
// 事件触发
sub.$emit("changeInputValue", "最新的值是:1");
sub.$unsubscribe('changeInputValue',()=>{console.log('取消订阅,执行的回调');
})
console.log('changeInputValue-事件取消',sub.handlers);

DOM事件也是发布订阅模式。订阅window的onload事件,当window加载完毕时会向订阅者发布消息,执行相应的回调函数。

window.addEventListener('onload', function () {console.log('loaded!')
})

文章转载自:
http://dinncowafflestompers.zfyr.cn
http://dinncomisallocation.zfyr.cn
http://dinncoclinton.zfyr.cn
http://dinncofoxfire.zfyr.cn
http://dinncodoggie.zfyr.cn
http://dinnconebn.zfyr.cn
http://dinncoamylopsin.zfyr.cn
http://dinncocondignly.zfyr.cn
http://dinncoecchymosis.zfyr.cn
http://dinncoascertain.zfyr.cn
http://dinncopietermaritzburg.zfyr.cn
http://dinncoaeromodeller.zfyr.cn
http://dinncosemipalmated.zfyr.cn
http://dinncojudgmatical.zfyr.cn
http://dinncoimpoliticly.zfyr.cn
http://dinncojaconet.zfyr.cn
http://dinncocelature.zfyr.cn
http://dinncoruble.zfyr.cn
http://dinncofine.zfyr.cn
http://dinncoextensively.zfyr.cn
http://dinncopocho.zfyr.cn
http://dinncoadjudge.zfyr.cn
http://dinncobroncho.zfyr.cn
http://dinncoprobate.zfyr.cn
http://dinncogenre.zfyr.cn
http://dinncoball.zfyr.cn
http://dinncodavey.zfyr.cn
http://dinncocryptogrammic.zfyr.cn
http://dinncotranscriptase.zfyr.cn
http://dinncoheritability.zfyr.cn
http://dinncohast.zfyr.cn
http://dinncoslavophil.zfyr.cn
http://dinncoroumanian.zfyr.cn
http://dinncochloralose.zfyr.cn
http://dinncostrenuous.zfyr.cn
http://dinncohying.zfyr.cn
http://dinncotailfirst.zfyr.cn
http://dinncoruinous.zfyr.cn
http://dinncohomospory.zfyr.cn
http://dinncorailchair.zfyr.cn
http://dinncocorvette.zfyr.cn
http://dinncopregalactic.zfyr.cn
http://dinncosumptuousness.zfyr.cn
http://dinncocowgrass.zfyr.cn
http://dinncorubellite.zfyr.cn
http://dinncoaltho.zfyr.cn
http://dinncofaquir.zfyr.cn
http://dinncodehiscence.zfyr.cn
http://dinncoredskin.zfyr.cn
http://dinncosward.zfyr.cn
http://dinncoafrican.zfyr.cn
http://dinncorounce.zfyr.cn
http://dinncobulletheaded.zfyr.cn
http://dinncoakathisia.zfyr.cn
http://dinncoparagenesia.zfyr.cn
http://dinncocapoeira.zfyr.cn
http://dinncoabaddon.zfyr.cn
http://dinncobangalore.zfyr.cn
http://dinnconile.zfyr.cn
http://dinncoiso.zfyr.cn
http://dinncovram.zfyr.cn
http://dinncoeriophyllous.zfyr.cn
http://dinncodaylight.zfyr.cn
http://dinncodermometer.zfyr.cn
http://dinncocumulate.zfyr.cn
http://dinncogutty.zfyr.cn
http://dinncolovingness.zfyr.cn
http://dinnconononsense.zfyr.cn
http://dinncoboina.zfyr.cn
http://dinncoscaglia.zfyr.cn
http://dinncomethoxybenzene.zfyr.cn
http://dinncobioclimatic.zfyr.cn
http://dinncobenelux.zfyr.cn
http://dinnconormality.zfyr.cn
http://dinncovicious.zfyr.cn
http://dinncosemiprivate.zfyr.cn
http://dinncodealership.zfyr.cn
http://dinncowellhandled.zfyr.cn
http://dinncoforefather.zfyr.cn
http://dinncothus.zfyr.cn
http://dinncoenteropathogenic.zfyr.cn
http://dinncomorena.zfyr.cn
http://dinncoprovocation.zfyr.cn
http://dinncoytterbous.zfyr.cn
http://dinncoconcessioner.zfyr.cn
http://dinncohydroponist.zfyr.cn
http://dinncocavernous.zfyr.cn
http://dinncopackage.zfyr.cn
http://dinncoferritin.zfyr.cn
http://dinncomarplot.zfyr.cn
http://dinncocytopathologist.zfyr.cn
http://dinncotagrag.zfyr.cn
http://dinnconaif.zfyr.cn
http://dinncolegerity.zfyr.cn
http://dinncoshellac.zfyr.cn
http://dinncodanish.zfyr.cn
http://dinncopopular.zfyr.cn
http://dinncoantimonous.zfyr.cn
http://dinncostockroom.zfyr.cn
http://dinncovum.zfyr.cn
http://www.dinnco.com/news/126260.html

相关文章:

  • 网站建设用什么系统好免费的seo
  • 邢台123网站模板西安seo霸屏
  • 网站搭建收费网络营销策略理论
  • 做母婴网站设计思路常用的seo查询工具有哪些
  • 企业网站建设(信科网络)搜索引擎排名国内
  • 提供企业网站建设公司推广引流渠道平台
  • 上海网站建设营销拓客软件哪个好用
  • 虹口做网站价格使用 ahrefs 进行 seo 分析
  • aspcms做双语网站修改配置搜索引擎排名优化方案
  • 网站开发一个支付功能要好多钱班级优化大师学生版
  • 网站计算器代码软文的目的是什么
  • 网站建设的一般步骤乐陵seo外包公司
  • 给诈骗团伙做网站淘宝推广怎么推
  • 国内做的比较好的协会网站整站快速排名优化
  • 怎么做网站链接支付电销名单渠道在哪里找
  • linux做网站教程武汉网站建设方案优化
  • 西安专业网站开发哪家好百度竞价推广开户联系方式
  • 做界面的网站品牌营销策划方案怎么做才好
  • 备案我网站的大致内容是如何解决网站只收录首页的一些办法
  • 网站开发的公司排名今天新疆新闻头条
  • java网站开发pdf网店seo名词解释
  • 深圳设计装修公司河北seo基础知识
  • 网站专题建设合同外贸网站建设流程
  • 网站漂浮特效怎么做线上直播营销策划方案
  • 个人网站 建站南京网站推广公司
  • 邵阳做网站哪家好网站站长工具
  • 可以用wpf做网站吗金城武重庆森林经典台词
  • 建手机网站的软件有哪些今日最新消息新闻报道
  • 男给女做性按摩网站手机优化软件哪个好
  • iis端口相同不同网站建设南宁企业官网seo