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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:43:55+00:00 2026-05-28T00:43:55+00:00

I was playing around with javascript prototype chain inheritance and i came accross this

  • 0

I was playing around with javascript prototype chain inheritance and i came accross this funny behaviour.

I have a parent class and a child class

//class parent
function parent(param_1) {
    this.param_1 = param_1;

    this.getObjWithParam = function(val) {
        console.log(this);
        console.log("Constructor value in parent class " + this.param_1);
        console.log("tguha ----> parent,  val " + val);
    };
};

//class child
function child(param_1) {
    parent.call(this, [ param_1 ]);
};

var childObj = new child(100);
childObj.getObjWithParam(200);

and i get the output as

**>child**
Constructor value in parent class 100
tguha ----> parent,  val 200

and nowhere i’m doing //child.prototype = new parent();
and still the parent class is inherited.

Could anyone help me by explaining this scenario please.

  • 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-28T00:43:55+00:00Added an answer on May 28, 2026 at 12:43 am

    The word prototype does not appear in this code. So nothing is being inherited. You create a new child and then explicitly run the parent constructor function on that new child. The parent constructor function then add a method to to the new child.

    If you put getObjWithParam on parent.prototype.getObjWithParam instead then you will see that it will not carry over.

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

Sidebar

Related Questions

I've been playing around with prototypal inheritance in JavaScript and have been confused by
So I'm playing around with JavaScript and came across what I think to be
I have been playing around with this problem since yesterday. I can't seem to
I've been playing around with prototypal inheritance after reading http://javascript.crockford.com/prototypal.html and having a bit
I was playing around with Javascript creating a simple countdown clock when I came
I was playing around with arrays in Javascript today and noticed this little gem:
I'm very new to javascript and have been playing around with regular expressions. I'm
I have been playing around JavaScript for a year or so, one thing I
Possible Duplicate: Is JavaScript's Math broken? I have just started playing around with Javascript
I have been playing around with some CSS3 + JavaScript today. Below you have

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.