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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:18:27+00:00 2026-05-24T18:18:27+00:00

I have a main JavaScript file, we’ll call core.js that other file are dependent

  • 0

I have a main JavaScript file, we’ll call core.js that other file are dependent on.

In core.js I am defining an Object that will be required to exist in the dependent files.

core.js:

(function (){
/* base package */
var core = window.core = function() {
    // Throw an error, the core package cannot be instantiated.
    throw new Error("A package cannot be instantiated");
};
})();

utils.js

/* utils package */
core.utils = function() {
    // Throw an error, the core package cannot be instantiated.
     throw("A package cannot be instantiated");
};

/**
 * Utility: StringUtils
 */
core.utils.StringUtils = new Object();
core.utils.StringUtils.prototype = {

    /**
     * ltrim - Removes preceding whitespaces
     */
    ltrim: function(value) {
        var re = /\s*((\S+\s*)*)/;
        return value.replace(re, "$1");

    },

    /**
     * rtrim - Removes succeeding whitespaces
     */
    rtrim: function(value) {
        var re = /((\s*\S+)*)\s*/;
        return value.replace(re, "$1");

    },

    /**
     * trim - Removes preceding and succeeding whitespaces
     */
    trim: function(value) {
        return core.StringUtils.ltrim(core.StringUtils.rtrim(value));
    }
};

Currently, i am adding an id tag to the <script /> tag

<script id="core.js" src="core.js" type="text/javascript"></script>

and checking it’s existence before defining any new items in the core Object.

(function() {
    if (typeof (core) == 'undefined') {
        var script = document.getElementById("core.js");
        if (script == null)
            throw ("core.js is missing.");
        else
            throw ("Unknown Exception. core is undefined.");
    }
})();

Should I be concerned with cross browser compatibility? It is currently working in IE9 and FF5, but I want to make sure it works for all browsers.

Is there an alternative/better way to determine if a file was included or not?

  • 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-24T18:18:28+00:00Added an answer on May 24, 2026 at 6:18 pm

    That will work fine, since <script> tags are synchronous any Javascript after that tag will have access to core. If you want another method of doing the same thing, your could take Marc B’s suggestion and set a flag in core.js. The flag could also be part of the core object, like core.is_loaded = true; Then you just check if(core.is_loaded) in your other files.

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

Sidebar

Related Questions

I have a javascript file main.js and five html files 1.html,2.html,3.html,4.html,5.html I want to
We have a UI widget on our main UI that uses JavaScript to respond
I have a JavaScript file that embeds a widget on a website. I want
I read that concatenating and possibly gzipping a javascript file will make an application
I have to clear and redraw a raphael javascript main container. I've tried with
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
I have JavaScript inside a .wsf file and I'm getting the error: C:\bin\LDLSInfo.wsf(53, 34)
I have an HTML file with a couple of external JavaScript files. Here's an
This is my jQuery AJAX code and this javascript file is placed in C:\workspace\search-ui\search-ui\src\main\webapp\themes\client\javascript\agile.js
I have my JavaScript files on my main domain and I want to do

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.