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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:22:23+00:00 2026-05-28T19:22:23+00:00

I am having trouble wrapping my mind around primarily RequireJS. I see that it

  • 0

I am having trouble wrapping my mind around primarily RequireJS. I see that it is a good/necessary technology, but implementing it, for me, has been a real stretch. I greatly appreciate your help!

I am trying to develop a fairly flexible application with Backbone and RequireJS. The problem is that I am totally used to syntax like new Person() without having to specify dependencies. Is there an efficient way to use RequireJS with quite a number of models? I think my problem is always working with returns. I considered using a factory method to create the model with the require function, but doing so necessitates that the require function is synchronous, which completely defeats the purpose of RequireJS.

It just doesn’t seem right to have to require all of my models first and then include those in the instantiation function – or do I?

Do you have any suggestions or tutorials about how to structure and model an application like this?

Thank you for helping me out!

JMax

  • 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-28T19:22:24+00:00Added an answer on May 28, 2026 at 7:22 pm

    You can use what I call require js module pattern. If you know a group of classes are often used together you can do something like this.

    First you define each class in a separate file and then you define a module to hold them together

    Module.js
    
    define([
    
        './models/FirstModel',
        './models/SecondModel',
        './views/FirstView',
        './views/SecondView',
        'txt!./templates/template.tpl'
    
    ], function(FirstModel, SecondModel, FirstView, SecondView, template) {
    
        return {
            FirstModel: FirstModel,
            SecondModel: SecondModel,
            FirstView: FirstView,
            SecondView: SecondView,
            template: template
        }
    
    });
    

    And then when you want to use class from this module you just do

    define(['./Module'], function(Module) {
    
        var AView = Module.FirstView.extend({
    
            model: Module.FirstModel,
    
            render: function() {
    
                this.html(_.template(Module.template)(this.model.attributes));
    
                if (something) {
    
                    this.$el.append(new Module.SecondView().render().el);
                }
            }
        })
    
        return AView;
    });
    

    I don’t believe using modules defined with requirejs we should return an instance – we should always return a constructor or an object.

    You should totally embrace the defining and requiring – with time you’ll start to love it – without having to think much about adding/tracking dependencies etc. everywhere by hand or (so 2005!) having most of the stuff in one file 🙂

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

Sidebar

Related Questions

I'm using symfony 1.4 and am having trouble wrapping my mind around what seems
I am having trouble wrapping my mind around how to do this in linq.
I'm having trouble wrapping my mind around how to calculate the normal for a
I'm having trouble wrapping my head around how to write this query. A hypothetical
I am having trouble wrapping my head around how to make a Dojo Deferred
I'm having trouble wrapping my head around more advanced Rails query methods. In this
I'm having trouble wrapping my head around how to set this up. I have
I am having trouble wrapping my head around the concept of an array with
I'm having trouble wrapping my head around .NET DataTable events, handling, actions, etc. I
It seems like it should be simple enough, but im having trouble wrapping my

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.