我无法弄清楚如何this
在下面的render.onload
函数中访问。我知道答案可能涉及闭包,但我还不能完全理解它。
var PhotoModel = Backbone.Model.extend({
initialize: function() {
this.uploadPhoto();
},
uploadPhoto: function() {
var file = this.get("file");
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(event) {
// I don't have access to "this" here...
this.dataURL = event.target.result;
}
}
});