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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:29:29+00:00 2026-05-26T17:29:29+00:00

Judging by the # of javascript inheritance questions here I am going to assume

  • 0

Judging by the # of “javascript inheritance” questions here I am going to assume my question was probably already answered elsewhere and I am just not understanding the other solutions…or javascript in general apparently.

My question is, why does the code below ( http://jsfiddle.net/Se9ZW/2/ ) print “test5” instead of “test1”?

var fake = { value:'test1'};
var fake2=fake;
fake2.value='test5';
document.getElementById('debug').innerHTML=fake.value;

These seems like something that is pretty obvious and so I am kinda embarassed to even be bringing it up but I guess ya gotta learn somehow.

  • 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-26T17:29:30+00:00Added an answer on May 26, 2026 at 5:29 pm

    fake and fake2 are references to the same object, so it is totally expected that they behave that way. It has nothing to do with inheritance.

    Now, if you wanted to inherit, one way (quite naive, I might add) would be to do it like this:

    var fake = { value:'test1'};
    var fake2 = Object.create(fake); //creates a new object with fake as prototype
    fake2.value = 'test5'; // "overrides" the value property from the prototype
    console.log(fake.value);
    

    and the output then would be:

    test1
    

    Note that this is from ECMAScript Edition 5 – which is fairly recent and may not work in every JavaScript engine implementation out there.

    There are several way to implement/use inheritance in JavaScript. I am going to refer you to one of the explanations in accepted answer here.

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

Sidebar

Related Questions

I'm trying to attach multiple Behaviors to an UIElement (which, just judging from the
I'm performing a thought-experiment which, judging by other questions, isn't so novel after all,
Judging from the lack of info around, I'm guessing the following question maybe a
There is a program called PC^2 (a programming contest judging system). You can submit
I am building programming contest software. A user's program is received by our judging
The default Cassandra systems keyspace system is present in all Cassandra installations. Judging from
Judging from this Wikipedia article on cipher modes and other things I've heard about
Judging from the title, I kinda did my program in a fairly complicated way.
Judging from the result of my last inquiry , I need to calculate and
Judging by the comments on issue 554 , I would think that Fusion Tables

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.