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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:54:51+00:00 2026-06-15T04:54:51+00:00

I was trying to implement an interface like architecture in JS as followed in

  • 0

I was trying to implement an interface like architecture in JS as followed in C#. And met with a stumbling block. Here is the code sample:

    // Interface for UIBuilder classes
    function IUIBuilder() {
        this.addUserToList = function () {
            alert('parent: added');
        };
    }

    // Class implementing the IUIBuilder
    function ChatUIBuider() {
        IUIBuilder.prototype.addUserToList = function () {
            alert('child: added');
        };
        IUIBuilder.prototype.removeUserFromList = function () {
            alert('child: removed');
        };

        return new IUIBuilder();
    }

In the first class, I’ve defined a method addUserToList which I override in the second class ChatUIBuider. Also added one more method removeUserFromList to the base class using its prototype.

My issue is, the addUserToList method still invokes the parent class method even after it has got overridden in the child class. Why?

    var builder = new ChatUIBuider();
    builder.removeUserFromList(); // Invokes the child class method. - CORRECT
    builder.addUserToList(); // Invokes the base class method- WHY??

Could anyone tell me if this is the correct way I am doing?

  • 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-15T04:54:53+00:00Added an answer on June 15, 2026 at 4:54 am

    I suggest this construct :

    function IUIBuilder() {
    };
    IUIBuilder.prototype.addUserToList = function () {
        alert('parent: added');
    };
    
    // Class extending the IUIBuilder
    function ChatUIBuider() {
    }
    ChatUIBuider.prototype = new IUIBuilder();
    ChatUIBuider.prototype.addUserToList = function () {
            alert('child: added');
    };
    ChatUIBuider.prototype.removeUserFromList = function () {
            alert('child: removed');
    };
    

    ChatUIBuider extends IUIBuilder and inherits its functions but overrides the addUserToList function.

    In the following code, both constructors will be called but only the overriding addUserToList function will be called :

    var chat = new ChatUIBuider();
    chat.addUserToList();
    

    See demonstration

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

Sidebar

Related Questions

I'm trying to implement a iGoogle like dashboard interface using widgets that get their
I'm trying to implement a twitter iPhone app like interface. (Swipe to replace view
I'm trying to implement a user interface like above and looking for a good
I'm currently trying to implement a StopWatch class. The interface is something like: interface
I am trying to implement some interface changes in my app, based on the
I'm trying to implement a REST interface under IIS5.1/ASP-classic (XP-Pro development box). So far,
I am currently trying to implement a marker interface in c#. But I haven't
I'm trying to implement a generic java interface in scala. I have looked at:
I am trying to implement a Stack in java (using the list interface: Interface
I am trying to implement my persitent classes using interfaces. I have created the

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.