I'm using: https://github.com/blueimp/jQuery-File-Upload
Basically, I need to be able to save the current done
callback and call it in my own done
callback which is unbelievably complicated (I'm not familiar with jquery ui widgets).
Here's the code I'm trying to get to work to no avail:
var $el = $('#fileupload');
$el.fileupload();
var olddone = $el.fileupload('option', 'done');
$el.fileupload('option', 'done', function(e, data) {
data = ... manipulate data ...;
return olddone(e, data);
});
I've tried various variations on the theme:
return olddone.call(this, e, data);
and:
return olddone.call($el.data('fileupload'), e, data);
and:
return olddone.call($el[0], e, data);
And all errors basically tell me that this
is not correct and the context is not right for all the following calls. What am I doing wrong? How can I more or less subclass a specific callback but still use/call the original callback?
What's worse, is that copying the source of the done
callback in place of olddone
(instead of saving a reference and calling it) doesn't seem to work either.
What is this
in the context of a jQuery UI Widget options function? Why is this so convoluted? What am I missing?
EDIT:
After reading some widget documentation, it seems that all the methods are always called with the widget instance as this
, so why wouldn't the following work right?
olddone.call($el.data('fileupload'), e, data)
UPDATE:
I'm trying to preserve the done:
callback in options
that are here: https://github.com/blueimp/jQuery-File-Upload/blob/75d11179fd9c248c061c8eb428782bb556c8db0a/js/jquery.fileupload-ui.js#L139
Figured out that I was misusing the data passed in and I really just needed to use it correctly. This is the final code I needed to get this working.
The
olddone.call(this, ...)
turned out to still be necessary for some reason. Not sure whythis
was inherited from the current context and was instead undefined.