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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:51:37+00:00 2026-05-23T00:51:37+00:00

What are some current rules of thumb for implementing JQuery namespaces to host general

  • 0

What are some current “rules of thumb” for implementing JQuery namespaces to host general purpose utility functions?

I have a number of JavaScript utility methods scattered in various files that I’d like to consolidate into one (or more) namespaces. What’s the best way to do this?

I’m currently looking at two different syntaxes, listed in order of preference:

  //******************************
  // JQuery Namespace syntax #1
  //******************************
  if (typeof(MyNamespace) === "undefined")
  {
     MyNamespace = {};
  }

  MyNamespace.SayHello = function ()
  {
     alert("Hello from MyNamespace!");
  }

  MyNamespace.AddEmUp = function (a, b)
  {
     return a + b;
  }

  //******************************
  // JQuery Namespace syntax #2
  //******************************
  if (typeof (MyNamespace2) === "undefined")
  {
     MyNamespace2 =
     {
        SayHello: function ()
        {
           alert("Hello from MyNamespace2!");
        },

        AddEmUp: function (a, b)
        {
           return a + b;
        }
     };
  }

Syntax #1 is more verbose but it seems like it would be easier to maintain down the road. I don’t need to add commas between methods, and I can left align all my functions.

Are there other, better ways to do 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-23T00:51:38+00:00Added an answer on May 23, 2026 at 12:51 am

    For the record, I ended up using the first syntax:

    $(function ()
    {
       //********************************
       // PREDIKT NAMESPACE
       //********************************
    
       if (typeof (Predikt) === "undefined")
       {
          Predikt = {};
       }
    
       //********************************
       // PREDIKT.TIMER NAMESPACE
       //********************************
    
       if (typeof (Predikt.Timer) === "undefined")
       {
          Predikt.Timer = {};
       }
    
       Predikt.Timer.StartTimer = function ()
       {
          return new Date().getTime();
       };
    
       Predikt.Timer.EndTimer = function ()
       {
          return new Date().getTime();
       };
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current setup : I have an entity object with some properties, among them
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have some unit tests that expects the 'current time' to be different than
i have some files located in c:\MyApp\file.txt and current executing assenbly in in debud
Is there some way to replicate rails' link-to-unless-current? Ie. if i have a list
I have an ASP.NET website in which I am loading some validation rules from
I have a system I'm building that seems to call for some complex rules
I was recently looking around at some of the features my current web host
I am looking for some stats on current browsers for how long it takes
For my current project I want to be able to load some classes from

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.