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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:22:21+00:00 2026-06-11T15:22:21+00:00

I am trying to figure out how to start off some structure for a

  • 0

I am trying to figure out how to start off some structure for a new page.

The page is called ‘Orders’ and it will have a couple of tabs on it for now: ‘OrdersTab’ and ‘TasksTab’

I’ve got my layout setup like so:

//Namespace for the 'Orders' page.
var Orders = (function () {
    "use strict";
    var tabs = $('#OrdersTabs').tabs();
    var ordersTab = new OrdersTab();
    var tasksTab = new TasksTab();

    //Public methods:
    return {

    };
})(); //Load when ready.

My intention here is to have the Orders namespace be in charge of loading the tabs. I am struggling with understanding how to keep my OrdersTab and TasksTab in the same ‘namespace’ as Orders. Ideally, another page would not be able to instantiate an OrdersTab.

//Namespace for the 'OrdersTab' from the 'Orders' page.
function OrdersTab() {
    "use strict";
    var ordersGrid = $('#OrdersGrid');
    var ordersGridPager = $('#OrdersGridPager');

    ordersGrid.jqGrid({
        url: '../Orders/GetOrders/',
        datatype: 'json',
        colNames: ['Name', 'Description'],
        colModel: [
            { name: 'Name', index: 'Name', sortable: false, width: 150 },
            { name: 'Description', index: 'Description', sortable: false, width: 300 }
        ],
        gridview: true,
        height: 'auto',
        rowNum: 10,
        pager: ordersGridPager,
        viewrecords: true
    });

    //Public methods:
    return {

    };
};

Orders is located in Orders.js and OrdersTab is located in OrdersTab.js. It seems to me that a new OrdersTab could ‘accidentally’ be created by someone else, or the function name made ambiguous accidentally. Is it possible to wrap up OrdersTab inside of the Orders ‘namespace’ while also keeping it in a separate file? I think separate files are necessary in case each tab grows larger than expected / allow for the introduction of additional tabs in the future.

Furthermore, I was wondering if it was possible to use the same setup structure between both files. It seems awkward to me that I assign to a variable for Orders, but just create a function with OrdersTab. Maybe that is OK and standard, though, I just would like to know.

  • 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-11T15:22:22+00:00Added an answer on June 11, 2026 at 3:22 pm

    There are several solutions, ranging everywhere from putting everything inside of that one function, which you don’t want to do, down to completely sandboxing every module, and giving them a messaging system to communicate with one another (similar to how MacOS runs).

    A happy medium would be to build a loading-system into your primary application:

    var APPNAME = (function () {
        var load = function (name) { /* load name.js */ },
            add = function (name, implementation) { this[name] = implementation; };
            public_interface = {
                load : load,
                add : add
            };
    
        return public_interface;
    }());
    

    Feel free to build in a promise system, or a mediator system. With these, you can fire off custom events, internal to your application, to handle dependencies and initialization, and all of the rest.

    Then you’ll have the ability in other files to do something like:

    // module-1.js
    APPNAME = APPNAME || {add: function () {}}; // the second part is to die without error
    APPNAME.add("publiclyAccessibleName", function () { /* whatever you need it to be */ });
    

    So in your actual document, you just need to use APPNAME.load("modulename"); to load “modulename.js”, which will then be accessible as APPNAME.publicName as whatever you decide it to be.

    And again, you can further abstract that… …you could have an addPublic and an addPrivate for services or for modules. You could store your modules inside of a hidden object, instead of on the public object, you can use the implementation as a constructor, or as another IIFE to return another object.

    In advanced sandboxes, you’d probably load these into a modules object, and then when you initialize each module, you could pass its initialize function an object which has access to, say your JS Library (jQuery/Dojo), and the application’s messaging system.

    In order to be really sandboxed, that system-object would only be an instance, rather than a shared object, so that tampering with it would only seal that module off, rather than messing with anything else in the system.

    …of course, by this time, you’re really, really involved, and this could relatively-securely scale a large application.

    I’m not saying you should go that far overboard. What I am saying is that there’s always more, and things can always be abstracted further, to accomplish what you need to.

    I like that about JS.

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

Sidebar

Related Questions

I'm trying to start off using FBJS, and I can't figure this out. The
I am trying to figure out how to grab the start directory for my
After trying to figure out why a Capistrano task (which tried to start a
trying to figure out why this is happening - I have an input text
I am trying to figure out how to start and stop a serial interface.
I'm new to QT, and am trying to figure out the best means of
I'm new to using threads and just trying to figure things out. My end
I have been trying to figure this out all day. I've searched SO and
Trying to figure out how I can do this properly. The print_r looks like
Trying to figure out why my silverlight app suddenly just displays nothing (right click

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.