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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:59:02+00:00 2026-06-03T23:59:02+00:00

I to try create my first javascript app with backbone.js And I found strange

  • 0

I to try create my first javascript app with backbone.js
And I found strange behaviour, don’t understand difference between 2 piece of code
One works well and second seems not work.

That show alert on homepage and ‘#test’ url

var AppRouter = Backbone.Router.extend({
    routes:{
        "": 'index',
       "test": 'test'
    },
    index: function(){
        alert('index');
    },
    test: function(){
        alert('test');
    }    
});
var app = new AppRouter();
Backbone.history.start();

And that not work, but Backbone.history.hanlers looks identical

var router = new Backbone.Router({
    routes:{
        "": 'index',
       "test": 'test'
    },
    index: function(){
         alert('index');
    },
    test: function(){
         alert('test');
    }    
});
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-03T23:59:04+00:00Added an answer on June 3, 2026 at 11:59 pm

    The difference between the two bits of code is that in the first one you are creating a new class called AppRouter whereas in the second one you are just creating a plain Backbone.Router class.

    I may be misunderstanding, but it seems you are saying that the first example works, and the second one doesn’t?

    The reason the second example does not work is because Backbone.Router only accepts the routes hash as an argument to it’s constructor. The index and test functions you have passed are not created as functions on the object.

    If you want to pass the routes hash to the constructor you still need to extend Backbone.Router with the actual routing functions. For example:

    var AppRouter = Backbone.Router.extend({
        index: function(){
            alert('index');
        },
        test: function(){
            alert('test');
        }    
    });
    var app = new AppRouter({ 
        routes:{
            "": 'index',
           "test": 'test'
        }});
    Backbone.history.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to create the a table the very first time, I always
I try to create a very simple app using windows API. I've done some
I try to create 2 buttons inside my app case WM_CREATE:{ hWnd =CreateWindowEx(NULL, LBUTTON,
I'm currently having a problem with events in Javascript. I'll first try to explain
I am finalizing the first version of my javascript app, and I would like
First off: I'm fairly new to zk. I try to create a component that
I have a JavaScript widget (a piece of embedded JS and HTML code) that's
Possible Duplicate: Simplest code for array intersection in JavaScript I am writing an app
I want to try create something like Zend's Server Pagecache. What I want to
I try to create a progress bar that displays the progress of a parser

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.