jqXHR object removes itself and container from an array
I am storing jquery ajax objects inside an array so that I can manually
cancel the cal,if it has not returned, based on user triggered events.
JavaScript
var ajaxCalls = [];
ajaxCalls[0] = $.ajax({...});
$("#cancelButton").on("click", function() { ajaxCalls[0].abort(); });
The problem that exists is that the jqXHR object disappears from the array
after the abort() method is called.
Now this looks great when it comes to managing the memory of my objects as
it is magically removing itself and cleaning up nicely. However, it leaves
an anti-pattern in my code where it looks like I am not cleaning up after
myself. It also defeats the purpose of me creating a remove companion
method to my add method.
Is there a reason for this? If my array contains more then 1 object it
re-sizes itself completely appropriately.
This array if the letters were jqXHR objects
['a', 'b', 'c', 'd']
Becomes this array when jqXHR object 'b' completes
['a', 'c', 'd']
Reading the code, one would expect that this would occur
['a', null/undefined, 'c', 'd']
WHY?
No comments:
Post a Comment