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

  • Home
  • SEARCH
  • 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 8505647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:22:47+00:00 2026-06-11T02:22:47+00:00

I have been looking at some code for a while now and can’t decide

  • 0

I have been looking at some code for a while now and can’t decide on the best practice to apply in this situation:

Let’s say that we have a view that has n-subviews. I have come across two practices for initializing them

1 Inside intitialize

initialize: function() {
  this.subViews = [];
  this.subViewModelCollection.each(function(model) {
    var view = new SubView({model: model});
    this.subViews.push(view);
    this.$el.append(view.el);
  }, this);
},

render: function() {
  _.invoke(this.subViews, 'render');
}

2 Inside render

initialize: function() {
  ... // render handles the subviews
},

render: function() {
  this.subViews = [];
  this.subViewModelCollection.each(function(model) {
    var view = new SubView({model: model}).render(); // render optional
    this.subViews.push(view);
    this.$el.append(view.el);
  }, this);
}

now these are just crude samples, but they demonstrate my dilemma. Should the initialize or the render -function be responsible for initializing the subviews? Personally I have been a strong advocate for the latter version, but some code I saw made me sway towards the former.

So, WHERE do you initialize your subviews, WHY do you do it there and WHY is it better than the other option?

  • 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-11T02:22:49+00:00Added an answer on June 11, 2026 at 2:22 am

    You should maximize the amount of work you do in initialize, as that will only be done once, and minimize the amount of work you do in your render function which may typically be called many times (for instance in a single page application or responsive webpage).

    If you know your render method for your subviews will never change the generated html, then you can probably also call the render method for the subviews in the initialize method as well, and simply appending the rendered element in the “main view”.

    If the render methods for both your subviews and main view is only called once anyway (as part of loading a page or whatever) it probably does not matter how you do it, but generally minimizing the amount of work to be done in the render functions is probably good advice.

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

Sidebar

Related Questions

I have been looking for some time for this and I can't seem to
I have been looking through some code on an open source project recently and
I have been looking for an answer for some time now, hope you could
I have been looking for a 5-Star rating control for a while now and
I have been looking into refactoring some old code into a new WCF service,
I have been looking around online for a while now for methods of integration
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
Hi i have been looking for some solutions but i have found nothing... Is
I have been looking into AWS spot instances for some jobs however instead of
I have been looking around on the web and found some articles about the

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.