JavaScript code not working within a callback
In the following JavaScript code, if warnBeforeNew is false, the file open
code works. However, it doesn't if warnBeforeNew is true, instead giving
an error "Uncaught TypeError: Cannot read property 'root' of undefined".
I don't know if this is to do with scoping, but how do I get the file
loading code to work within the callback? Thanks.
Editor.prototype.open = function(path) {
if (Editor.warnBeforeNew==true){
this.showDialog({
dialogLabel: 'You have unsaved changes. Are you sure you want to
discard them and open a different file?',
submitLabel: 'Discard',
cancelLabel: 'Cancel',
submitCallback: function() {
Editor.warnBeforeNew=false;
this.filesystem.root.getFile(path, {}, this.load.bind(this),
error.bind(null, "getFile " + path));
}
});
} else {
this.filesystem.root.getFile(path, {}, this.load.bind(this),
error.bind(null, "getFile " + path));
}
};
No comments:
Post a Comment