How do I delete a previously assigned handler?
var deferred = $.Deferred();
var callback = function(n) {
console.log('Test ' +n);
}
deferred.progress(callback);
deferred.notify(1);
$(deferred).off('progress', callback); // It doesn't work =(
deferred.notify(2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Is there a way built into jQuery to remove jQuery.Deferred handlers?
2
Answers
I found out that jQuery.Deferred uses jQuery.Callbacks. This allowed us to write a wrapper for jQuery.Deferred and pull the ability to manage handlers to the top. Below is an example.
No, there’s no function to remove already-registered callbacks on a
$.Deferred()
.