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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:22:07+00:00 2026-06-08T08:22:07+00:00

I have a site that uses a javascript object to hold various functions and

  • 0

I have a site that uses a javascript object to hold various functions and variable data.

var Site = {
    Page: {
    ...some functions...
    },
    Player: {
    ...more functions and variables...
    }
}

The problem I’m faced with is that the header file where the script resides has grown to around 500 lines of code. I would like to break the sections like Page and Player up into separate files for easier manipulation. An obstacle of this is that some of the functions rely on output from PHP, and must remain on the base page. Is there a way that I can include separate files into the object and preserve the structure already in place?

  • 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-08T08:22:09+00:00Added an answer on June 8, 2026 at 8:22 am

    Note that by convention, variables starting with a capital letter are reserved for constructors.

    File 1:

    var Site = Site || {};
    
    Site.Page = {     
        ...some functions...
    }
    

    File 2:

    var Site = Site || {};
    
    Site.Player = {
        ...more functions...
    };
    

    You can also use an extend function so that you declare an object literal, then copy the proerties and values to a base object. Or you can use an IIFE to assign functions. This is handy if you are doing feature detection and creating different functions depending on the outcome.

    var Site = Site || {};
    
    (function(global) {
    
      function Player() {
        // stuff
      }
    
      global.Site.Player = Player;
    
      if (test) {
        global.Site.someFn = function() {
          // stuff 1
        };
    
      } else {
        global.Site.someFn = function() {
          // stuff 2
        };
      }
    
      ...
    
    }(this));
    

    or some version of the above.

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

Sidebar

Related Questions

I have this form in my site that uses JavaScript to clear the fields
I have a site that uses javascript to launch a css overlay of a
I'm developing a site that uses JavaScript, HTML5 and CSS3 heavily. I have no
I am creating a micro site that uses Javascript for data visualisation. I am
I have an HTML5 demo site ( http://html5beats.com/ ) that uses JavaScript to detect
I have a site that uses the Facebook JavaScript API to allow users to
I have some code that uses JavaScript templates to create some HTML, including some
I have a web site I created that uses Python, HTML, and javascript. The
I have an auction site that has a javascript timer counting down. For some
I have a site that uses a large centered background image, which naturally loads

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.