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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:15:00+00:00 2026-06-13T08:15:00+00:00

I have a pretty basic Backbone app which uses a router to instantiate views

  • 0

I have a pretty basic Backbone app which uses a router to instantiate views and collections. In playing around with the app, I noticed that if I put the line of code instantiating the router

 router = new DocsRouter();

at the top of the application.js file, then the app didn’t work; it had to be at the bottom of the file. Yet, this didn’t make sense to me. Why should the location of this line of code matter, since everything important to start the app happens inside the router? Shouldn’t I be able to trigger the router from anywhere?

 window.DocsRouter = Backbone.Router.extend({

        initialize : function() {

            this.docs = new Docs();

            this.docs.fetch();


            this.docFormView = new DocFormView({ collection : this.docs });
            this.docsView = new DocsCollectionViewTempo({ collection : this.docs });
            this.docsView.render();

            this.route("doc/:id", "doc", function(id){
                console.log(id, this.docs.get(id).toJSON());
            });
        },

        routes : {
            "" : "root",
            "about" : "about",
            "doc/:id" : "doc"
        },

        root : function() { console.log('Vous êtes à la racine');},
        about : function() { console.log('A propos : ceci est un tutorial BackBone');},
        doc : function(id) { console.log(id, this.docs.get(id).toJSON()); }
    });

 router = new DocsRouter();
 Backbone.history.start();
  • 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-13T08:15:01+00:00Added an answer on June 13, 2026 at 8:15 am

    No. You cannot create an instance of DocRouter before DocRouter has been declared.

    window.DocsRouter = Backbone.Router.extend({..});
    router = new DocsRouter();
    

    The order of these two lines has to be this. Before the first line DocRouter does not exists thus you can not instantiate it.

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

Sidebar

Related Questions

I have a pretty basic app I am working on that uses a navigation
I have a pretty basic app flow that is quite linear, so it fits
I have a pretty basic 'User' model, control & views for a Rails app.
I have a pretty basic jquery script which uses an h2 as a trigger
I have a pretty basic internal iOS app that I want to send a
I have a pretty basic X11 app that I run on Linux that I'm
I might have pretty basic question about regex. I have the following regex, which
I have a pretty basic slideshow fading between images. On top of that slideshow
I am writing a pretty basic php app and have created a pretty big
I'm pretty basic with .net But basically I've been told that to have session

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.