创新实训项目分析(十六)

2021SC@SDUSC
接下来是对Tool类进行分析
Tool类具有基础枚举,用来供他类引用
在这里插入图片描述
tool类具有以下基础参数
在这里插入图片描述
具有基础的get、set方法

Tool.prototype.initialize = function(id, tooltip, icon, slot, callback){
  this._id = id;
  this._tooltip = tooltip;
  this._icon = icon;
  this._slot = slot;
  this._callback = callback;
  this._on_click = this.onClick.bind(this);
  this._on_hover = this.onHover.bind(this);
  this._on_leave = this.onLeave.bind(this);
};
// --------------------------------------------------------------------------------
// * Getter & Setter
// --------------------------------------------------------------------------------
Object.defineProperty(Tool.prototype, 'id', {
  get: function() {
    return this._id;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'tooltip', {
  get: function() {
    return this._tooltip;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'icon', {
  get: function() {
    return this._icon;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'slot', {
  get: function() {
    return this._slot;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'callback', {
  get: function() {
    return this._callback;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'on_click', {
  get: function() {
    return this._on_click;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'on_hover', {
  get: function() {
    return this._on_hover;
  },
  configurable: true
});
Object.defineProperty(Tool.prototype, 'on_leave', {
  get: function() {
    return this._on_leave;
  },
  configurable: true
});

实现点击事件、覆盖事件、离开事件

Tool.prototype.onClick = function(){
  if(this._callback.on_click) {
    this._callback.on_click.call(this);
  }
};
Tool.prototype.onHover = function(){
  if(this._callback.on_hover) {
    this._callback.on_hover.call(this);
  }
};
Tool.prototype.onLeave = function(){
  if(this._callback.on_leave) {
    this._callback.on_leave.call(this);
  }
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值