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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:18:56+00:00 2026-05-29T05:18:56+00:00

I follow this pattern to organize my js application. As that example says our

  • 0

I follow this pattern to organize my js application.

As that example says our application should has the single entry point. File application.js doing that work.

// Filename: application.js

var chat = {
  // Create this closure to contain the cached modules
  module: function() {
    // Internal module cache.
    var modules = {};

    // Create a new module reference scaffold or load an
    // existing module.
    return function(name) {
      // If this module has already been created, return it.
      if (modules[name]) {
        return modules[name];
      }

      // Create a module and save it under this name
      return modules[name] = { Views: {} };
    };
  }()
};

// Using the jQuery ready event is excellent for ensuring all 
// code has been downloaded and evaluated and is ready to be 
// initialized. Treat this as your single entry point into the 
// application.
jQuery(function($) {

  $(document).ready(function(){
    var foo = new Application.module('Chat').Collection();
 }); 
});


// Filename: chat-module.js

(function(chat){
  chat.Model = Backbone.Model.extend({ ... }),
  chat.Collection = Backbone.Collection.extend({ ... }),
})(Application.module('Chat'));

It seems well but if try to define chat module for example and invoke it later I have the following error:

Uncaught TypeError: Property 'Collection' of object #<Object> is not a function

I think that error due jQuery ready invokes when chat-module.js not available yet.
How can I resolve that problem?

  • 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-29T05:18:57+00:00Added an answer on May 29, 2026 at 5:18 am

    Your code creates an object and assigns it to the global variable chat, which has a module function as a property:

    var chat = {
        module: function...
    };
    

    …but then when you use it, you use Application.module rather than chat.module.

    Application.module('Chat')
    

    and

    var foo = new Application.module('Chat').Collection();
    

    It seems to me that your chat variable should be called Application.

    Also note that you’re using module in two different ways, both with new and without. Without would be the correct use based on your code. It will work both ways because module returns a function (which is an object), and so that will override the normal new behavior, but it means that using new serves no purpose and is misleading to someone reading the code.

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

Sidebar

Related Questions

Using mod_rewrite, how could I turn URLs that follow this pattern: http://example.com/index.php?id=14 Into this
I have a bunch of python methods that follow this pattern: def delete_session(guid): conn
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
There are a few windows service projects in our codebase that follow this model,
I am trying to follow this example (from p137 of Rob Pickering's Foundations of
I am trying to follow this example but I can't understand this part: Imagine
I have a set of files which the names follow this pattern: xxx -
This almost seems silly but what is the most reliable pattern to follow when
In my business layer, I need many, many methods that follow the pattern: public
I follow this rule but some of my colleagues disagree with it and argue

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.