Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8605657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:53:38+00:00 2026-06-12T02:53:38+00:00

If a backbone model (or collection) may or may not already exists, how do

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:53:40+00:00Added an answer on June 12, 2026 at 2:53 am

    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:

    var mymodels = {};
    
    mymodels.A = _.extend({}, mymodels.A, {
        url: "http://www.google.com"
    });
    
    mymodels.A = _.extend({}, mymodels.A, {
        initialize: function(){
            this.set('mixin', 'TRUE'); 
        }
    });
    mymodels.A = Backbone.Model.extend(mymodels.A);
    
    var model = new mymodels.A({'new': 'TRUE'});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my Model View and Collection : window.Report = Backbone.Model.extend({}); window.ReportCollection = Backbone.Collection.extend({
My model and collection looks like this. var MyModel= Backbone.Model.Extend({ foo: function(){ alert(is not
I have the following model and collection: var UserModel = Backbone.Model.extend({ url: 'api/user', idAttribute:'username',
Models: class Device extends Backbone.Model url: '/device' initialize: -> console.log Device model created... @set
let's say I have : var Book = Backbone.Model.extend(); var Collection = Backbone.Collection.extend({ model:
Imagine a Model/Collection like: var AModel = Backbone.Model.extend({ defaults: { a: 'a string', b:
I have the following Backbone.js model and collection: // Model lr.Event = Backbone.Model.extend({}); //
var ContractModel = Backbone.Model.extend({ url: ${g.createLink(controller:'waiverContract', action:'index')} }) var contract = new ContractModel({}); contract.fetch();
When you override backbone sync, both model/collection .save()/fetch() uses the same backbone sync method,
while reading docs of backbone i can't understand how to add model to collection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.