If a backbone model (or collection) may or may not already exists, how do you extend or mixin?
Here’s what I’ve tried:
mymodels.A = ('A' in mymodels ? mymodels.A : Backbone.Model).extend({
/* url, initialize, parse, etc... */
});
or
mymodels.A = ('A' in mymodels ? mymodels.A.prototype : Backbone.Model).extend({
/* url, initialize, parse, etc... */
});
or
mymodels.A = _.extend('A' in mymodels ? mymodels.A : Backbone.Model, {
/* url, initialize, parse, etc... */
});
Thoughts?
Edit:
mymodels.A = (mymodels.A || Backbone.Model).extend({
/* url, initialize, parse, etc... */
});
Edit2:
Took a different approach….see answer below
This accomplished what I was trying to do….which was create model in pieces. In the end, I create an object in pieces and pass the whole object to Backbone.Model.extend: