0

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.

flightsearch
  • 79
  • 2
  • 10
  • Please don't use that [jQuery pattern](http://stackoverflow.com/a/12143833/1048572). – Bergi May 05 '15 at 17:19
  • thank you for the hint to the other question. You would like to explain why not to use the jQuery pattern? I think of it of quite elegant but not so experienced here. Can you point me to a better pattern? – flightsearch May 05 '15 at 17:56
  • I find it unnatural to use an extra `init` function instead of the constructor itself. If you want to support calls without `new`, just use a [preamble like this](http://stackoverflow.com/q/22211755/1048572). – Bergi May 05 '15 at 21:03

0 Answers0