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 8115783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:34:46+00:00 2026-06-06T03:34:46+00:00

I recently started learning backbone and was wondering what would be the best way

  • 0

I recently started learning backbone and was wondering what would be the best way of grouping model attributes in a backbone model? I am thinking of having a specialized view that will handle a subset of the model’s attributes.

For example, if I have a car model, and I want to group all the information about the engine, so that I can pass these attributes to a view maybe? Something like car.engine_info

Car = Backbone.Model.extend({
    initialize: function() {
        this.engine_info = this._set_engine_info();
    }
    _set_engine_info: function() {
        return {displacement:this.get('displacement'), horsepower: this.get('horsepower')};
}
  • 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-06T03:34:48+00:00Added an answer on June 6, 2026 at 3:34 am

    You should consider making multiple models, not return a separate set of data. That data won’t have the power of backbone behind it for event handling and updates. You are creating a new object that just has properties and values.

    Instead make models for each component

    A car has – An engine, features, etc.

    Engine = Backbone.Model.extend({
      defaults: {
          cylinders: 4,
          horsepower: 180
      }
    });
    
    Features = Backbone.Model.extend({
        defaults: {
          powerwindows: true,
          airconditioning: true
        }
    });
    

    Then mixin the feature set into a car model by overriding the constructor

    Car = Backbone.Model.extend({
        defaults: function () {
           return {
             engine: new Engine(),
             features: new Features()
           };
        },
        constructor: function ( attrs ) {
            attrs || ( attrs = {} );
            if ( attrs.engine ) {
                attrs.engine = new Engine( attrs.engine );
            } 
            // etc
            Backbone.Model.prototype.constructor.call( this, attrs );
        }
    });
    

    Another options would be to create a car and create some decorator functions that add the features, but frankly I prefer the method listed. Now you can have separate components listen to their own changes

    var car = new Car({
        engine: { // props },
        features: { //props }
    });
    
    car.get( 'features' ).on( 'change:powerwindows', // some function, this );
    

    The true power behind all of this is to separate responsibility of a car’s overall feature set. A car shouldn’t have to worry about all of it’s parts. Let the engine worry about the engine and let the features worry about the features.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have only started learning python recently. I would still be considered a beginner.
I recently started learning Clojure and I'm having a bit of difficulty wrapping my
Ok, so I recently started learning jQuery, but I'm having trouble with a little
Having only recently started learning the 'new' OpenGL (programmable as opposed to fixed-function, I
I recently started learning about HttpModules and made my first one. I was wondering
I just recently started learning the Scala language and would like to do it
I've recently started learning/using django; I'm trying to figure out a way to have
I recently started learning the CodeIgniter framework and i was wondering about one thing:
I've recently started learning and exploring the basics of GUI programming in Java. Having
I have just recently started learning Haskell and I am having a lot of

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.