blog icon indicating copy to clipboard operation
blog copied to clipboard

面向对象实战

Open yongheng2016 opened this issue 8 years ago • 0 comments

tab组件

预览:http://js.jirengu.com/manicihuqe

页面上由很多类似的东西,但我只用考虑我自己就可以了
页面有很多tab,我只考虑其中一个

  • 1.功能需求
  function Tab(ct){
	xxx
  }
  
new Tab(ct1)  //第一个tab功能
new Tab(ct2)  //第二个tab共能

  • 2.写功能
function Tab(ct){
	this.属性1  //注意this和实例的联系
	this.属性2
	...
}

  • 3.功能分离
    1. init
    2. bind

banner

同样,有多个轮播,我只用关心其中一个就行

  • 1.功能需求
function Caroucel{
	xxx
}

new Caroucel(ct1)  //传入容器1
new Caroucel(ct2)  //传入容器2
  • 2.功能实现(根据具体某个轮播写功能)
  • 3.代码封装

懒加载、曝光加载

  • 1.功能需求
function Exposure(){
	xxx
}

new Exposure(target, function (){
	xxx   //曝光后,执行回调
})  
  • 2.功能实现

function Exposure(target, callback){
	this.init
	this.bind
	//功能函数
	...
} 

// 有事件绑定的地方给this重命名保存
// _this = this
  • 3.分情况 1.文字 2.图片

yongheng2016 avatar Jul 30 '17 12:07 yongheng2016