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);
}
};