0

First of all, I'm sorry for my awful English.

I'm working on a code that allows you to detect single click, double click and triple. It works great, except the world this. For some reason, it window.

Here is my code:

        $.fn.dblorone = function(single, dbl, triple){
            var DELAY = 300,
                clicks = 0,
                timer = null,
                clicked = "s",
            i.on("click", function (e) {
                clicks++; //count clicks
                if (clicks === 1) {
                    clicked = "s";
                    setTimeout(function () {
                        if(clicked == "s"){
                            single();
                            clicks = 0;
                        }
                    }, DELAY);
                } else if (clicks === 2) {
                    clicked = "d";
                    setTimeout(function () {
                        if(clicked == "d"){
                            dbl(); 
                            clicks = 0; 
                        }
                    }, DELAY);
                }else{
                    clicked = "t";
                    triple();
                    clicks = 0;
                }
            }).on("dblclick", function (e) {
                e.preventDefault();
            });
        };

Here is a jFiddle: http://jsfiddle.net/9ab0g1o9/

GINCHER
  • 628
  • 4
  • 20
  • I see no use of `this` in the code you provided. In any case, `this` is a fundamental part of JavaScript that needs to be learned as part of the language. –  Apr 02 '15 at 17:00
  • 2
    http://jsfiddle.net/9ab0g1o9/1/ - use `.call(i)` for each of your callbacks. This way you will be able to force your element as a context. – Artyom Neustroev Apr 02 '15 at 17:02
  • you shoud use an reference to the `body` tag, not `this`. since it isn't a call of a element, `this` represents the `window` element. `this` always references "who made the call" – Giovanni Perillo Apr 02 '15 at 17:03

0 Answers0