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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:58:04+00:00 2026-05-26T21:58:04+00:00

How can I go about making a child class override a privileged method of

  • 0

How can I go about making a child class override a privileged method of a base class?

If its not possible, is there another way to achieve what I am trying to accomplish in the simple code example below?

I cannot convert the baseclass function parseXML() to public because it requires access to private variables

    function BaseClass()
    {
        var map = {};

        // I cannot make this function public BECAUSE it accesses & changes private variables
        this.parseXML = function( key, value )
        {
            alert("BaseClass::parseXML()");
            map[key] = value;
        }
    }

    function ChildClass()
    {
        BaseClass.call(this);
        this.parseXML = function( key, value, otherData )
        {
            alert("ChildClass()::parseXML()");

            // How can I call the base class function parseXML()?
            //this.parseXML();  // calls this function not the parent function
            //MyClass.prototype.doStuff.call
            BaseClass.prototype.parseXML.call(this, key, value);  // fails
            //BaseClass.prototype.parseXML(); // fails

            // perform specialised actions here with otherData
        }
    }

    ChildClass.prototype = new BaseClass;

    var a = new ChildClass();
    a.parseXML();
  • 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-26T21:58:05+00:00Added an answer on May 26, 2026 at 9:58 pm
    function BaseClass() {
        var map = {};
        this.parseXML = function(key, value) {
            alert("BaseClass::parseXML()");
            map[key] = value;
        }
    }
    
    function ChildClass() {
        BaseClass.call(this);
        var parseXML = this.parseXML;
        this.parseXML = function(key, value, otherData) {
            alert("ChildClass()::parseXML()");
            parseXML.call(this, key, value);
        }
    }
    
    ChildClass.prototype = new BaseClass;
    
    var a = new ChildClass();
    a.parseXML();
    

    Live Example

    Basically you cache the privileged method (which is only defined on the object) and then call it inside the new function you assign to the privileged method name.

    However a more elegant solution would be:

    function BaseClass() {
        this._map = {};
    };
    
    BaseClass.prototype.parseXML = function(key, value) {
        alert("BaseClass::parseXML()");
        this._map[key] = value;
    }
    
    function ChildClass() {
        BaseClass.call(this);
    }
    
    ChildClass.prototype = Object.create(BaseClass.prototype);
    ChildClass.prototype.parseXML = function(key, value, otherData) {
        alert("ChildClass()::parseXML()");
        BaseClass.prototype.parseXML.call(this, key, value);
    }
    
    var a = new ChildClass();
    a.parseXML();
    

    Live Example

    Also bonus implementation using pd

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

Sidebar

Related Questions

Can anyone tell me the best way to go about making an iPhone application
How can I go about making my routes recognise an optional prefix parameter as
I'm making an iPhone app that has information about different video games. How can
how can i go about making a custom NSMenu for a menulet such as
There are plenty of great answers to questions about making a standalone executable, but
I can't find any information about making a tcp/ip packet logger in a book.
Note: This question is not about making a custom dropdown. It's only about possibilities
First of all, this is not about making the PictureBox control transparent. It's about
How exactly can I go about making a select tag readonly. I've read that
I'm thinking about making a 3D point and click game, is it possible to

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.