好的,所以我的主类的模块模式如下:
Var draggable = {};
(function(){
var initialMouseX = undefined;
var initialMouseY = undefined;
var startX = undefined;
var startY = undefined;
var draggedObject = undefined;
var startDragX = undefined;
var startDragY = undefined;
var eventHandler = undefined;
var canvas = undefined;
var that = this;
this.setCanvasObject = function(cnv){
canvas = cnv;
}
this.setEventHandler = function(eH){
eventHandler = eH;
};
this.setClickable = function(element){
...
};
this.setDraggable = function(element){
...
};
this.startDragMode = function(ev){
...
};
this.dragMouse = function(ev){
....
};
this.setPosition = function(dX, dY){
...
};
this.releaseElement = function() {
...
};
}).apply(draggable);
这是我的父类或原型类,使用我的模块设计模式。
这是我的子类,使用相同的模块模式:
var toolbarHeader = {};
(function(){
this.__proto__ = draggable;
var that = this;
this.__proto__.startDragMode = function(ev){
var evt = ev || window.event;
var target = evt.target || evt.srcElement;
target = target.parentNode;
that.startDrag(target);
initialMouseX = evt.clientX;
initialMouseY = evt.clientY;
eventHandler.addEventSimple(document,'mousemove', that.dragMouse);
eventHandler.addEventSimple(document,'mouseup', that.releaseElement);
};
}).apply(toolbarHeader);
我想要做的是使用toolbarHeader类来覆盖父方法,并在其余时间使用parent方法。
目前它发出错误,因为它无法找到that.releaseElement,that.startDrag和that.dragMouse。
我做错了什么?这是我应该如何使用继承?这是一个很好的设计吗?