In the given code snippet above, the variable this
inside the _onChunkComplete
method refers to the XHR request by default. However, is there a way to modify this so that it represents the actual Uploader
object instead?
function Uploader(file, options) {
// ... code here ....
this.upload_request = new XMLHttpRequest();
this.upload_request.onload = this._onChunkComplete;
}
Uploader.prototype = {
// ... code here ...
_onChunkComplete: function() {
if (this.range_end === this.file_size) {
console.log('done');
return;
}
this.range_start = this.range_end;
this.range_end = this.range_start + this.chunk_size;
if (!this.is_paused) {
this._upload();
}
}
// ... more code here...
};
var test = new Uploader(formFile, {});
test.start();