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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:17:03+00:00 2026-06-09T11:17:03+00:00

All my models and support modules are name-spaced. Currently I initialize them like this.

  • 0

All my models and support modules are name-spaced. Currently I initialize them like this. I call initAll() on some sort of onload.

MC stands for Model-Controller and Su for Support.

/**
 **  initAll
 */

MC.initAll = function() {

    MC.MATweet.init();
    MC.MABAdder.init();

    MC.MASettings.init();

    MC.MUserTry.init();
    MC.MUserNew.init();
    MC.MUserExist.init();

    Su.UserOut.init();
    Su.Media.init();
}

Obviously, each has it’s own init() function. I plan on updating this to use hasOwnProperty to check for the init property and from there, if it exists call it. This would make this function a loop basically…which checks the namespace.

Are there other ways…to initialize models. Is this a good way for a light-weight application?

  • 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-09T11:17:06+00:00Added an answer on June 9, 2026 at 11:17 am

    One way is to loop though all your models like this, and in each model check for the property init. If it is there call it. This makes initialization automatic…you just have to define it in each model.

    for ( var key in MC ) {
        if( MC.hasOwnProperty( key ) ) {
            if( MC[key].hasOwnProperty( 'init' ) ) {
                MC[key].init();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have methods in all of my models that look like this: def formatted_start_date
class A(models.Model): def calculate(self): # calculate some field based on all self.b_set instances class
I have a class which models all categories and they can be ordered hierarchically.
I'm writing a custom admin stuff and need to get all registered models in
I already started a project, and the models are all synced and everything.
All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)
Greetings On all my controllers I recycle the same code that wraps my models
I am trying to find all of the types in the Models namespace within
I just finished creating several models and a had to separately write all of
Is there any command available for generating all missing spec files for existing models

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.