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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:57:49+00:00 2026-05-31T03:57:49+00:00

Is it best to place it in the global object or within a View

  • 0

Is it best to place it in the global object or within a View instance?

(i’m thinking that if I place it on the global such as: window.todos = new Todos(), it would pollute the global object if there are a lot of collections; however, putting it inside a view may make things a bit confusing)

Based on your experience, where is the best way to place it?

  • 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-05-31T03:57:50+00:00Added an answer on May 31, 2026 at 3:57 am

    I think this really depends on your application. What I have generally done is to establish a namespace for the application, and put collections there, as well as views:

    // namespace for the application
    var app = {};
    
    // collection classes are also within the namespace
    app.ToDos = Backbone.Collection.extend({ ... });
    
    // and collection instances are in the namespace as singletons
    app.todos = new app.ToDos();
    

    For a large application, you might go further, establishing sub-namespaces for model classes, view classes, router classes, and application instances. There are a few advantages to this, though none of them is really crucial:

    • Having collections available in the app namespace allows them to be referenced from multiple views if necessary

    • When debugging, you have access to the collections in the console

    • Establishing a new namespace for your application allows you to add a number of new global variables without polluting the global namespace or worrying about bad interactions with other libraries

    The last point is a really good argument for namespacing your app, but it doesn’t necessarily follow that your collections need to be at the top level of your namespace, or available globally at all. The main question is how important it is for you to be able to access the collection outside a particular parent view (or parent model). If you’re sure the collection is a one-off, it might be cleaner to keep it out of the app namespace entirely.

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

Sidebar

Related Questions

Would someone confirm the best place for a partial view in ASP.NET MVC? My
What is the best place in servlet for Hibernate code that returns HibernateSessionFactory ?
currently i'm thinking on where's the best place in my code where i must
In an app that uses MongoDB, when/where is the best place to make database
Where is the best place to find information on binding redirects? or maybe just
Where is the best place to find custom compnonents? Ideally a repository, as opposed
Where is the best place to put the constant in a condition? Left side
Where is the best place to implement caching in a web based app? At
I am not sure where the best place to put validation (using the Enterprise
I was wondering where is the best place to initialize members of the singleton

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.