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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:52:31+00:00 2026-05-26T07:52:31+00:00

Continuing my quest to learn more about Backbone.js I have arrived to a situation

  • 0

Continuing my quest to learn more about Backbone.js I have arrived to a situation where I would want to instantiate a Backbone application programmatically. This occurs in a situation where the entire site/page is not a Backbone application, but instead a modal is opened, then populated (base structure for Backbone app), and then I would like to trigger the Backbone application (whose JavaScript was also loaded when the modal was opened). I would prefer to instantiate the Backbone app ‘manually’ if possible, i.e. so that it would not auto-execute when its script is loaded.

The typical Backbone format I have been using is like this:

var myApp = (function($) {

    var myModel = Backbone.Model.extend({
        ...
    });

    var modelInstance = new myModel({
        ...
    });        

    var myView = Backbone.View.extend({
        ...
    });

    var viewInstance = new myView({
        ...
    });

}

But the above is automatically executed when the script file is loaded, then the instantiated view(s) attempt to bind/render to their associated DOM elements, etc. Is there a way to defer the execution of the anonymous function so that I could load the script when the modal is being prepared but then trigger the Backbone app on command at a [slightly] later point?

Many thanks for any insights on this.

  • 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-26T07:52:32+00:00Added an answer on May 26, 2026 at 7:52 am

    You should put your app’s components into an object with an init method, which you can then call when your modal dialog opens. Here’s an example structure:

    window.App = {
      Models: {},
      Views: {},
      Routers: {},
      init: function () {
        var app = new window.App.Routers.main;
        Backbone.History.start();
        return app;
      }
    };
    
    window.App.Models.Foo = Backbone.Model.extend({
      // ...
    });
    
    window.App.Views.FooView = Backbone.View.extend({
      // ...
    });
    
    window.App.Routers.main = Backbone.Router.extend({
      // ...
    });
    
    window.modalDialog.onOpen = function () {
      window.app = window.App.init();
    };
    

    The above assumes you have a global variable called modalDialogrepresenting your modal window, which calls its onOpen callback when the window is shown.

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

Sidebar

Related Questions

Continuing on from this question programmatically creating a drop down list I would like
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
On a quest to learn a bit about Python and sockets I'm writing a
I'm continuing to learn C and would like to adhere to whatever is the
Continuing to learn WCF, I'm trying to write a small program that would with
Continuing on this problem , but I'll reiterate: For a homework assignment I have
My quest of starting to use namespaces in PHP keeps continuing. This time PHPUnit
I would like to mention before continuing that I have looked at other questions
Starting around Friday night, and continuing as of this morning, we have been seeing
Continuing my quest of learning Java by doing a simple game, i stumbled upon

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.