This is similar to the typical mysql / db operation.
You might want to structure this differently:
this.model = MyModel.find({id:id});
try {
this.doSomething();
} catch (e) {
if (e instanceof SomeSpecificException) {
var fetchPromise = this.model.fetch();
fetchPromise.done(
this.doSomething.bind(this)
);
}
}
What's going on here?
Try/Catch - , - . , . Fetch / ( , ). (), doSomething, . .
?
- :
var Deferred = require('simply-deferred');
Backbone.Model.prototype.fetch = function(options) {
var dfd = Deferred();
Backbone.Model.prototype.fetch.call(
this,
_.extend({ success: dfd.resolve.bind(this) }, options)
);
return dfd.promise;
}
, , - : Backbone.Model.prototype.fetch Backbone. , , , Backbone-Relational fetch . , .
? , - node , promises , .