I am having issues attempting to preserve uploader as the this context when onSubmit is called. Can any JS gurus help out?
uploader: {
init: function(){
var that = this;
var fileUploader = new Uploader.FileUploaderBasic({
button : $("#upload-btn")[0],
action : "/filesCollection",
onSubmit : that.onSubmit
});
_.bindAll(this, this.onSubmit); // attempting to bind 'this'
},
onSubmit: function(id, fileName){
console.log(this); // still refers to 'fileUploader' object :(
}
}
Results in the following error:
Uncaught TypeError: Cannot read property 'bind' of undefined
Problem Solved: http://jsfiddle.net/WilsonPage/BE3Lp/41/
Several Important Things I Discovered:
_.bindAll()must be called before the function is assigned.thisyou wish to bind.this) and they must be in string form!this) then omit any function names and have the object (this) as the only argument eg._.bindAll(this)Hope this helps some confused peeps like me!