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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:24:57+00:00 2026-06-14T04:24:57+00:00

I have a module like the following defined in one file define([‘mod1’, ‘mod2’], function

  • 0

I have a module like the following defined in one file

define(['mod1', 'mod2'], function (mod1, mod2) {

    var IndexView = Backbone.View.extend({

        ...

    });

    return new IndexView;

});

And this is required from within another file (my Backbone router file) with the following

require(['src/views/index']);

Can I make the returned IndexView object accessible from within the router’s scope without resorting to storing a reference in my app’s namespace?

  • 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-14T04:24:58+00:00Added an answer on June 14, 2026 at 4:24 am

    Passing around instances of Backbone views/models with require.js will quickly make your life very unhappy. It would be much easier to make your modules only return the definitions of the views/models, that way can instantiate them all inside the same scope.

    So if you make your view module return just the definition:

    // IndexView module
    define(['dep1', 'dep2'], function (dep1, dep2) {
    
        var IndexView = Backbone.View.extend({
    
            ...
    
        });
    
        return IndexView;
    
    });
    

    You can then instantiate it inside your router:

    // our main requirejs function
    requirejs(['path/to/indexview'], function (IndexView) {
    
        var AppRouter = Backbone.Router.extend({
    
            initialize: function () {
    
                // bind our IndexView to the router
                this.IndexView = new IndexView();
    
            }
    
        });
    
        // start the app
        var app = new AppRouter();
    
    });
    

    That way your code is still modular with Require.js, but you can pass around the router’s scope using this.

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

Sidebar

Related Questions

I have a setup like this. var element = $(.module-panel, this.el); $('.module-panel:not('+element+')').hide(); What I'm
I have a simple custom exception defined like like the following but I don't
I am using url rewrite module (from here ). I have following rule defined
I have some actions defined like action = '[module]/[action]' & submit. The result is
It's common to see CommonJS modules defined using the following idiom: (function() { var
I have a module like the following module MyModule def self.included(base) base.extend ClassMethods end
I have a dictionary called fsdata at module level (like a global variable). The
I have made a YUI module a little like the code shown below, which
I have a Perl module and I'd like to be able to pick out
So I have something like this: module top (..., out,...); ... output [0:1] out;

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.