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

网站公司建设网站价格怎样在手机做自己的网站6

网站公司建设网站价格,怎样在手机做自己的网站6,网站建设织梦源码,asp.net 4.0网站开...关于EventBus事件总线 事件总线#xff0c;实现 on, once, emit, off on, once 是注册函数#xff0c;存储起来emit时找到对应的函数#xff0c;执行off找到对应的函数#xff0c;从对象中删除 注意 区分on和onceon绑定的事件可连续执行#xff0c;除非offonce绑定的函数…关于EventBus事件总线 事件总线实现 on, once, emit, off on, once 是注册函数存储起来emit时找到对应的函数执行off找到对应的函数从对象中删除 注意 区分on和onceon绑定的事件可连续执行除非offonce绑定的函数 emit 一次即删除也可未执行而被 off数据结构上标识出 on 和 once 实现方案1 代码实现使用参数区分 on和once class EventBus {/*{key1: [{fn: fn1, isOnce: false},{fn: fn2, isOnce: false},{fn: fn3, isOnce: true},],key2: []}*/private events: {[key: string]: Array{fn: Function; isOnce: boolean}}constructor() {this.events {};}on(type: string, fn: Function, isOnce: boolean false) {const events this.events;if (events[type] null) {events[type] []; // 初始化 key 的 fn 数组}events[type].push({fn, isOnce});},// 这里是初步版本once_origin(type: string, fn: Function) {const events this.events;if (events[type] null) {events[type] []; // 初始化 key 的 fn 数组}events[type].push({fn, isOnce: true});},once(type: string, fn: Function, isOnce: boolean false) {this.on(type, fn, true);},off(type: string, fn?:Function) {if (!fn) {// 解绑所有 type 的函数this.events[type] [];} else {// 解绑单个 fnconst fnList this.events[type];if (fnList.length) {this.events[type] fnList.filter(item.fn ! fn);}}},emit(type: string, ...args: any[]) {const fnList this.events[type];if (fnList null) return;// 注意this.events[type] fnList.filter(item {const { fn, isOnce } item;fn(...args);// 处理once, 它执行一次就要被过滤掉if (!isOnce) return true;return false;})} }const e new EventBus(); function fn1(a: any, b: any) {console.log(fn1, a, b)}; function fn2(a: any, b: any) {console.log(fn2, a, b)}; function fn3(a: any, b: any) {console.log(fn3, a, b)};e.on(key1, fn1); e.on(key1, fn2); e.once(key1, fn3);e.emit(key1, 10, 20); // 触发 fn1, fn2, fn3 e.off(key1, fn1); e.emit(key1, 100, 200); // 触发 fn2实现方案2 代码实现: 拆分保存 on和once class EventBus {private events: { [key: string]: ArrayFunction} // {key1: [fn1, fn2]}private onceEvents: {[key: string]: ArrayFunction} // 结构同上constructor() {this.events {}; // 存储 onthis.onceEvents {}; // 存储 once}// on 触发on(type: string, fn: Function) {const events this.events;if (events[type] null) events[type] [];events[type].push(fn);},once(type: string, fn: Function) {const onceEvents this.onceEvents;if (onceEvents[type] null) onceEvents[type] [];onceEvents[type].push(fn);},// 解绑事件off(type: string, fn: Function) {if (!fn) {// 解绑所有事件this.events[type] [];this.onceEvents[type] [];} else {// 解绑单个const fnList this.events[type];const onceFnList this.onceEvents[type];if (fnList.length) {this.events[type] fnList.filter(curFn curFN! fn);}if (onceFnList.length) {this.onceEvents[type] onceFnList.filter(curFn curFN! fn);}}},emit(type: string, ...args: any[]) {const fnList this.events[type];const onceFnList this.onceEvents[type];if (fnList.length) {fnList.forEach(f f(...args));}if (onceFnList.length) {onceFnList.forEach(f f(...args));// once 执行一次就删除这里更简单代码更简洁this.onceEvents[type] [];}} }// 测试用例同上此处省略总结 区分 on, once合理的数据结构比算法优化更有效
http://www.w-s-a.com/news/695853/

相关文章:

  • 直播网站建设需要什么软件有哪些室内设计效果图怎么做
  • 宁波网站建设电话网络推广外包一年多少钱
  • 检索标准的网站怎么制作企业网站
  • 下列关于网站开发中网页发布wordpress 粘帖图片
  • 网站建设遇到的问题及对策宁波网站建设营销推广
  • 各大招聘网站常州百度快速优化
  • 做网站线稿软件有哪些做门户网站需要注册公司吗
  • 建设企业网站模板下载优化方案怎么写
  • 做像淘宝网的网站网站单页面制作
  • 网站建设流程表龙岩网站建设较好的公司
  • 龙岗建站费用手机免费建立网站吗
  • 江门高端网站建设怎样制作wordpress手机主题
  • 淘宝网站如何在邮件里做超链接wordpress图片投票插件
  • 镇平哪家网站做的好招聘网站如何建设
  • 建网站一般多少钱幸福里wordpress怎么可视化构建页面
  • 广东网站建设建站模板主机托管公司
  • 网站开发师是做什么的网站域名在哪里备案
  • 什么是网站国内高速空间国外做3d模型的网站
  • 效果建网站的公凡科网登陆
  • 网站域名续费多少钱在线制作图片软件
  • 济南城乡住房建设厅网站中国会议营销网站
  • 展示类网站cms网站seo方法
  • 莒县做网站的公司设计师网站模版
  • 顺德顺的网站建设备份的网站建设方案书
  • 如何做网站广告山东电商网站建设
  • 新手建什么网站赚钱吗WordPress搜狗不收录
  • 石家庄招聘哪个网站做的好网站设计建设公司服务商
  • 建设公司网站大概需要多少钱建站平台和网站开发的区别
  • 淄川区住房和城乡建设局网站门户网站模板源码下载
  • 室内设计公司 网站建设建站塔山双喜