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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:33:18+00:00 2026-05-18T22:33:18+00:00

Simple questions. function p() { function A() { this.random = random; } A.prototype.newfunc =

  • 0

Simple questions.

    function p()
    {
        function A()
        {
            this.random = "random";
        }
        A.prototype.newfunc = function(){ alert("5");}

        function B()
        {

        }

        B.prototype = new A();

        var bObj = new B();
    }

Q1: When I set B’s prototype, I don’t get how B’s prototype property will update when/if A’s prototype is updated. I mean, to me it just inherits/copies all those properties. It’s not like it’s:

B.prototype = A.prototype

where B and A are one in the same.

Q2: After A is being returned and intialized to the prototype object of B, how does JS know not to include that prototype property? What I mean is, we never have this type of situation occuring as the JS interpreter knows just to chop off the property of A’s prototype:

B.prototype = new A(); //any A object has an associated prototype object
    B.prototype.prototype;//after initialization we no longer have the separate prototype property of A
  • 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-18T22:33:19+00:00Added an answer on May 18, 2026 at 10:33 pm

    Q1: You said it yourself – prototype is used for inheritance. Therefore B inherits all properties of A. When you add or change members of A, B will also change. They are not the same, as you correctly say, but A is B’s superclass, and if anything in the superclass changes, so will the subclass. You can, though, add members to B.prototype and change its behavior without changing A.

    try this:

        function A()
        {
        }
    
        A.prototype.alertname = function () 
        {
            alert (this.name);
        };
    
        function B()
        {
        }
    
        B.prototype = new A();
    
        var bObj = new B();
        var aObj = new A();
    
        A.prototype.name = "A"; 
        aObj.alertname(); // output is "A";
        bObj.alertname(); // output is "A";
    
        B.prototype.name = "B";
        aObj.alertname(); // output is "A";
        bObj.alertname(); // output is "B";
    

    Q2: Again, inheritance is different from composition. When you assign B.prototype, you don’t just put an object of type A in a place holder, but change the “blueprint” for all objects of type B. So when you access said blueprint, you don’t get an object of type A, but a blueprint of type B that contains a reference to the blueprint of type A. This blueprint will not have a member of type prototype, since prototype is not a “regular” member of either class. Add this to the code above:

    function iterateMembers ( obj ) {
        var str = "";
        for (var member in obj) {
            str += member + ", "
        }
        alert (str);
    }
    
    iterateMembers (aObj);
    iterateMembers (A.prototype); 
    

    Notice how neither aObj nor A.prototype contain a member “prototype”. Now call

    iterateMembers (A);
    alert (typeof(A));
    

    It should be obvious now that prototype is a member of the type function, and since function is not inherited by either A nor B (in fact, it can’t be inherited), neither of those contain a member with the name “prototype”.

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

Sidebar

Related Questions

No related questions found

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.