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

大学生创业服务网站建设方案做网站参考文献

大学生创业服务网站建设方案,做网站参考文献,建站公司怎么获客,网站分析与优化桥接模式 通过桥接模式,我们可以将业务逻辑与元素的事件解耦,也可以更灵活的创建一些对象 倘若我们有如下代码 const dom document.getElementById(#test)// 鼠标移入移出事件 // 鼠标移入时改变背景色和字体颜色 dom.onmouseenter function() { th…

桥接模式

通过桥接模式,我们可以将业务逻辑与元素的事件解耦,也可以更灵活的创建一些对象

倘若我们有如下代码

const dom = document.getElementById('#test')// 鼠标移入移出事件
// 鼠标移入时改变背景色和字体颜色
dom.onmouseenter = function() { this.style.color = 'white'this.style.backgroundColor = 'black'
}// 鼠标移出时恢复背景色和字体颜色
dom.onmouseleave = function () {this.style.color = 'black'this.style.backgroundColor = 'white'
}

这里我们不难看出有部分代码是重复的,只是改变了字体颜色跟背景色,这耦合度就高起来了,我们可以是这样

const changeColor = (dom, color, val)=>{dom.style[color] = val
}
const dom = document.getElementById('#test')
dom.onmouseenter = function () {changeColor(this, 'color', 'white')changeColor(this, 'backgroundColor', 'black')
}
dom.onmouseleave = function () {changeColor(this, 'color', 'black')changeColor(this, 'backgroundColor', 'white')
}

继续优化

const changeColor = (dom, color, val)=>{dom.style[color] = val
}
const changeColorAndBgColor = (dom, color, bgColor)=>{changeColor(dom, 'color', color)changeColor(dom, 'backgroundColor', bgColor)
}
const dom = document.getElementById('#test')
dom.onmouseenter = function () {changeColorAndBgColor(this, 'white', 'black')
}
dom.onmouseleave = function () {changeColor(this, 'black', 'white')
}

多元化

在使用不同角色有相同公用的方法时可以使用这种多元化来处理

const Speed = (x, y) => {this.x = xthis.y = y
}
Speed.prototype.run = function () { console.log('first run')
}
// TODO:其他内容
const Color = color => {this.color = color
}
Color.prototype.draw = function () {console.log('first draw')
}
// TODO:其他内容
const Speak = word => {this.word = word
}
Speak.prototype.say = function () {console.log('first say')
}
// TODO:其他内容// 创建一个 球
const Ball = function (x, y, color) {this.speed = new Speed(x, y)this.color = new Color(color)
}
Ball.prototype.init = function () {this.speed.run()this.color.draw()
}// 创建一个人
const People = function (x, y, say) {this.speed = new Speed(x, y)this.speak = new Speak(say)
}
People.prototype.init = function () {this.speed.run()this.speak.say()
}
...

通过桥接灵活的创建一个对象,针对不同的对象处理不同的业务逻辑,更灵活处理差异

http://www.sczhlp.com/news/94419/

相关文章:

  • 农业网站开发关键词工具网站
  • 海珠做网站广州免费建站找哪家
  • 公司网站策划福州网站建设新闻
  • 贵阳东方蜜蜂网站建设h5制作软件电脑
  • 做调查的网站‘如何搭建自己的小程序
  • 矩阵分解
  • wordpress数据库在哪黑帽seo关键词优化
  • 网站关键词优化方案分为几个步骤济南seo关键词排名工具
  • 企业网站 报价施工方案下载免费网站
  • 网站无后台可以上框架乐陵网站优化
  • 太原哪个网站制作最好用哪里有网站建设企业
  • 设计师门户网站源码新版网站上线
  • 做招聘网站用哪个cms三明市建设局网站
  • 做网站的销售怎么样如何进入公司网站后台
  • 新创建的网站网站上怎么做图片变换动图
  • 创建网站超市公司建网站怎么建
  • 煤炭网站建设企业筑巢做网站怎么样
  • 能不能模仿百度一样做搜索引擎网站wordpress修改上传文件大小
  • 重庆做网站费用4虎最新ip是多少呢有人知道吗
  • 全国哪个餐饮品牌的网站做的好处网站模式下做淘宝客
  • 最新73种暴利产品竞价单页网站制作带订单后台系统模板IT男做网站
  • 印尼请人做网站一个网站备案两个域名
  • 51做网站乐清本地网站
  • 企业网站栏目结构检测网站名 注册
  • 基于 Gitlab 实现 Go 的 CI/CD
  • 2025.9.11
  • 建设网站怎么收费标准wordpress主题知言
  • 网站后台英文如何建立网站?
  • 做本地的门户网站ol游戏大全排行榜
  • 专业的公司网站开发同性恋色做视频网站