I have written a draggable
parent class using a module pattern:
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);
Here is my child class, using the same module pattern:
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;
...
}).apply(toolbarHeader);
I want my toolbarHeader
's startDragMode
method to override the parent method, and inherit the rest of the parent's methods.
Is this how I should be using inheritance? Is this a good design? Please keep in mind that the module design pattern was chosen for extensibility and to avoid the hassle of namespacing and instantiation.
toolbarHeader
is not working as intended, and therefore off-topic. \$\endgroup\$ – 200_success Apr 27 '16 at 18:14