I am trying to produce my first very small framework/library.
I tried to find an answer here on SO for quite some time but wasn't able to figure it out myself :( The library Works ok except when I try to invoke a function after a double click. The function that handles the click is calling another one on the same prototype.
So here is the code (it is a bit jQuery like design to not call the new operator):
;(function(global, $){
"use strict";
var iSOT = function(divSelector, options){
return new iSOT.init(divSelector, options);
}
Next following is the prototype of iSOT.init:
iSOT.prototype = {
resetScale: function() {
diagramm.zoomed = false;
this.updateScale(diagramm.xAxis.initialRange);
},
updateScale: function(range) {
// some calculations here and then updating the DOM
},
doubleClick: function(event) {
var mouse = {}
// some not important calculation stuff
var positionHour = 12.42 // this value gets calculated in the lines before
if(!diagramm.zoomed) {
diagramm.zoomed = true;
this.updateScale([Math.round(positionHour)-6, Math.round(positionHour)+6]);
} else {
this.resetScale();
}
}
Followed by the iSOT.init part
iSOT.init = function(divSelector, options) {
// lot of default settings here
this.theSVG.on("dblclick", this.doubleClick);
// more unimportant stuff
this.updateScale();
};
Last but not least setting the Prototype and putting iSOT on the global context
iSOT.init.prototype = iSOT.prototype;
global.iSOT = iSOT;
}(window, jQuery));
If I double click i get "Uncaught TypeError: this.updateScale is not a function" (and I don't know why)
Can any of your experts please take a look for a split second and explain it to me.
Thank you for your help.
UPDATE:
I might be on the track finding the issue. this in the doubleClick function is actually the DOM element that was clicked on.