ftlabs / fastclick

Polyfill to remove click delays on browsers with touch UIs
MIT License
18.66k stars 3.23k forks source link

Why is FastClick instantiable? #173

Closed matthew-andrews closed 10 years ago

matthew-andrews commented 10 years ago

I feel this module could be a lot simpler (and potentially compress down a bit smaller) if it were written using the simple module pattern.

This would also allow us to make all but the attach method (and the previous new FastClick API) completely private (and therefore extra compressable).

We would also be able to remove these lines:-

        /** @type function() */
        this.onClick = function() { return FastClick.prototype.onClick.apply(self, arguments); };

        /** @type function() */
        this.onMouse = function() { return FastClick.prototype.onMouse.apply(self, arguments); };

        /** @type function() */
        this.onTouchStart = function() { return FastClick.prototype.onTouchStart.apply(self, arguments); };

        /** @type function() */
        this.onTouchMove = function() { return FastClick.prototype.onTouchMove.apply(self, arguments); };

        /** @type function() */
        this.onTouchEnd = function() { return FastClick.prototype.onTouchEnd.apply(self, arguments); };

        /** @type function() */
        this.onTouchCancel = function() { return FastClick.prototype.onTouchCancel.apply(self, arguments); };

Something like this:-

// The old instantiable API could be maintained like this:
var exports = module.exports = function FastClick(el) {
  exports.attach(el);
};

exports.attach = function(el) {
  // Add event listeners
}

/* The rest of the workings of FastClick could be made completely private */ 

Would this be worthwhile doing or am I missing something fundamental here?

matthew-andrews commented 10 years ago

Superseded by https://github.com/ftlabs/fastclick/pull/215.