I am having trouble with rewriting .proxy in jquery to Function.prototype.bind because .bind does not set guid on the bound function instances so that proxied event handlers can be removed without storing the instance of the proxied function.
If I replace .proxy with .bind, most scripts do not work anymore because of the missing guid being set.
How do I replace them to get rid of the deprecated messages and still have the scripts correctly working?
Below are some code lines of various JS scripts which do not work anymore when replaced with, for example, this.start.bind(this);.
Since .proxy does something significant different, I wonder why it is deprecated and moreover I wonder why in jQuery 4.0 the deprecated message appears as it was deprecated since jQuery 3.3 in 2018.
api.$element.on(this.eventType('start'), $.proxy(this.start, this));
api.$element.find('a').on(this.eventType('start'), function(e) {
this.timeStamp = e.timeStamp;
}).on('click', function(e) {
if (e.timeStamp - this.timeStamp > 400) {
e.preventDefault(); // prevent Click
}
});
$(document)
.on(this.eventType('move'), $.proxy(this.move, this))
.on(this.eventType('end'), $.proxy(this.end, this));
singleTapTimeout = setTimeout($.proxy(function() {
doubleTapStartTime=null;
//Trigger the event
$element.trigger('tap', [event.target]);
//Fire the callback
if(options.tap) {
ret = options.tap.call($element, event, event.target);
}
}, this), options.doubleTapThreshold );
$.proxydoes about the same thing, thatbinddoes in vanilla JS, I think?$.proxydoes a tiny bit more though, "One thing that jQuery.proxy does and Function#bind doesn't is setting guid on the bound function instances so that proxied event handlers can be removed without storing the instance of the proxied function." - whether that's in any way relevant for your use case, you'll have to test I suppose.