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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:30:33+00:00 2026-05-28T05:30:33+00:00

this is my very first post! I have a quick question in regarding inheritance

  • 0

this is my very first post! I have a quick question in regarding inheritance in javascript.

Of course the ‘extend2’ method is used to inherit child objects from the parent object using a for-in loop.

var extend2 = function (child, parent) {
    var c = child.prototype;
    var p = parent.prototype;
    for (var i in p) {
        c[i] = p[i];
    }
}

I’m currently reading “Object Oriented Javascript” by Stoyan Stefanov. It’s an awesome book.

Can anyone give me a good detailed explanation of how the child’s prototype object is not entirely overwritten or replaced but it’s just augmented?

How is it that when the objects inherit, they copy (primitive data types) instead of being looked up as a reference by using the extend2 function?

This would really help thanks!

  • 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-28T05:30:34+00:00Added an answer on May 28, 2026 at 5:30 am

    Primitive data types in javascript are passed via value, rather than reference. Thus when you copy a value it is actually copying it, not referring to it.
    Traditionally this is because a primitive was literally encoded in the memory in such a way (so the primitive int 7 would be encoded in memory as 0x7. When dealing with objects, however, they are encoded as a pointer to the memory location where the actualy object is. Thus, when you copy the value it is merely a copy of the reference pointer, not the object that that pointer referrs to.

    As for the fact that the child’s prototype is not replaced, that is because a prototype in java is merely another object. So a prototype may look like:

    {
        someField: 5
    }
    

    Which would indicate that instances of the object would initialize with a field called someField whose value is 5. with the above code, each entry in the object is copied to the child prototype, but nothing is deleted. Thus if the child prototype looks like:

    {
        someField: 10
        someOtherField: 3
    }
    

    Then performing the above extend2 command will overwrite someField, but not someOtherField, so the resulting prototype would be:

    {
        someField: 5
        someOtherField: 3
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first post here on stackoverflow and am very impressed by the
This is my very first question so I am a bit nervous about it
So this was one of my very first questions here, but I have a
This is very basic magento question i guess. I want to first get all
This may be a very mundane question, but this is the first jQuery plugin
i'm new to this kind of things. Kinda the first post ever regarding programming,
Hi this question or problem i have its very hard i have search and
This is my first post, but I have been using this site for a
This is my first post on here and I'm very new to iPhone developing,
this is my very first post! I'm pretty desperate so I'm going above and

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.