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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:25:23+00:00 2026-05-25T20:25:23+00:00

Just like C# or Java to put all my jQuery code in one .js

  • 0

Just like C# or Java to put all my jQuery code in one .js file, something like this:

namespace MySite
{
    class HomePage
    {
        function Init(params) { /*...*/ }
        //...
    }

    class ContactForm
    {
        function Validate() { /*...*/ }
        //...
    }
}

So you can call it in this way:

$(function () {
    MySite.HomePage.Init({a : "msg"});
});

I have this code, but doesn’t work:

$.namespace = function () {
    var a = arguments, o = null, i, j, d;
    for (i = 0; i < a.length; i = i + 1) {
        d = a[i].split(".");
        o = window;
        for (j = 0; j < d.length; j = j + 1) {
            o[d[j]] = o[d[j]] || {};
            o = o[d[j]];
        }
    }
    return o;
};

$.namespace('$.mysite');

$.mysite.Home = function () {

    function Home(params) {
        //...
    };

    Home.prototype = function () {
        Init: function () {
            alert("lol");
        }
    }
}; 

Is it possible to that in jQuery? (something similar or recommendations / examples to keep my jquery code organized. )
Thanks for your time and answers (sorry for my bad english).

  • 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-25T20:25:24+00:00Added an answer on May 25, 2026 at 8:25 pm

    Why not just put it inside a js object?

    var _o = {};
    _o.module1 = {};
    _o.module2 = {};
    
    _o.module1.someFunc = function(){//code};
    _o.module2.someFunc = function(){//code};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started with Java and downloaded Netbeans, i kind of like it, but
Just like in JavaScript : opener.document.getElementByName jQuery: ?? Is there any way to get
I make a call just like this: value = ./simulated_annealing Which is a C
I would just like your feedback on something. Basically I have a value called
Simply put, I would like to make java do what I want but I
I came across a few articles like this one , which suggest that some
I just played with Java file system API, and came down with the following
I have one main interface and an abstract class implementing all derivable methods (that
While learning Java I stumble upon this error quite often. It goes like this:
Here is what I would like to write in my java code: private <A

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.