filepicker.io - jQuery 'this' in callback -
i have filepicker.io dialog coming fine on success call seem lose 'this' context.
so code
var fileprocess ={ savefileinfo: function () { .....process info here }, selectfile: function () { filepicker.pick({ mimetype: 'image/*' }, function (blob) { this.savefileinfo(); }); } } so there "context: this" can in ajax call?
try creating new variable named self or me set current value of this outside callback. then, use closures, can access this callback through me or self.
like:
this.mesg = "hello"; var self = this; function handler() { alert(self.mesg); } later after context switch...
handler(); // alert 'hello' edit: oh nuts... realized won't work... try:
function handler() { alert(this.msg); } var newhandler = handler.bind(this); later...
newhandler(); function.prototype.bind() takes object, , returns function. whenever returned function called, object passed bind() used this.
Comments
Post a Comment