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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:37:11+00:00 2026-06-13T05:37:11+00:00

Good day. I am facing a rather simple trouble. I hope the community will

  • 0

Good day.
I am facing a rather simple trouble. I hope the community will help me.

Here’s what I have:
I have two JavaScript files: I have Parent class in the 1st, and Child class in the 2nd.
Now I’d like to hide these definitions from the global namespace. Of course, I could put them all into single JavaScript file and wrap it into a self-invoking anonymous function like this so that there will be only one instance of the child object (what I am trying to achieve):

var myChildObj = (function(){

    var ParentClass = function() {};    
    ParentClass.prototype = { 
        //some data
    };

    function extendsClass(childClass, parentClass, isRewrite) {
        for(var property in parentClass.prototype) {
            if (isRewrite || 
               (!isRewrite && 
                !isDefined(childClass.prototype[property]))) {                         
                childClass.prototype[property] = parentClass.prototype[property];
            }
        }

        childClass.prototype.parent =  parentClass.prototype;
    }

    var ChildClass = function() {}; 
    ChildClass.prototype = {
        //some data
    }

    extendsClass(ChildClass, ParentClass, false);
    return new PhotoGallerySingle();    
})();

But ParentClass declaration is rather huge and it will be not so programmers friendly to put it all in there.

So, how do you usually go about solving such problem? Thank you.

  • 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-13T05:37:12+00:00Added an answer on June 13, 2026 at 5:37 am

    I’m afraid you can’t do that.

    You could always attach it to some other object than the direct global namespace, but if you want to be able to use it in your second script, you need to make it public somewhere. Eventually, it will need to be accessible from the global object.

    Sorry.

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

Sidebar

Related Questions

Good Day, I have a simple working routine in Perl that swaps two words:
Good Day, I have two connection strings defined in my web.config file. <connectionStrings> <add
Good day, to stackoverflow community. I have run into a bug with regard to
Good day, Hope title is not confusing and i can be clear here. I
Good day pythonistas and the rest of the coding crowd, I have two QMainWindows
Good day, everyone! I have here a program that sorts 50,000 words from a
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have like 15 images I need to be buttons. I have
Good day, Stack Overflow. I have a homework assignment that I'm working on this

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.